Skip to content

Autolink codeql warning - #512

Closed
ChrisJohnNOAA wants to merge 6 commits into
ERDDAP:mainfrom
ChrisJohnNOAA:autolink-codeql-warning
Closed

ChrisJohnNOAA wants to merge 6 commits into
ERDDAP:mainfrom
ChrisJohnNOAA:autolink-codeql-warning

Conversation

@ChrisJohnNOAA

Copy link
Copy Markdown
Contributor

Description

I've started using CodeQL to highlight code concerns (it has a focus on security and performance issues). CodeQL highlighted the url extraction regexes as potentially extremely slow due to backtracking. While looking into fixes, I came across a library that does a better job than the regexes (there's some edge cases it handles correctly) and doesn't trigger CodeQL warnings.

Since I don't believe we have legitimate performance concerns with either approach I did not run a performance test.

Fixes CodeQL warnings. These aren't enabled on the main ERDDAP repo yet, and likely show up as security issues so I don't think I could link to them.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Checklist before requesting a review

  • I have performed a self-review of my code
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

ChrisJohnNOAA and others added 6 commits June 26, 2026 23:55
* Replace custom URL detection with autolink-java library

This change replaces the manual regex-based URL detection in String2.java
with the autolink-java library (0.12.0) for improved accuracy and
robustness.

Key changes:
- Added org.nibor.autolink:autolink dependency.
- Created LinkHelper.java to encapsulate link extraction logic and
  support ERDDAP's legacy backslash-based protocols (e.g., http:\\\\).
- Refactored String2.findUrl, containsUrl, and extractUrls to delegate
  to LinkHelper.
- Consolidated calling patterns in Erddap.java, TableWriterHtmlTable.java,
  and Table.java using LinkHelper.splitByLinks to avoid redundant detection
  passes.
- Updated String2Tests.java to reflect more accurate URL boundaries.

Co-authored-by: ChrisJohnNOAA <130599404+ChrisJohnNOAA@users.noreply.github.com>

* Replace custom URL detection with autolink-java library

This change replaces the manual regex-based URL detection in String2.java
with the autolink-java library (0.12.0) for improved accuracy and
robustness.

Key changes:
- Added org.nibor.autolink:autolink dependency.
- Created LinkHelper.java to encapsulate link extraction logic and
  support ERDDAP's legacy backslash-based protocols (e.g., http:\\\\).
- Refactored String2.findUrl, containsUrl, and extractUrls to delegate
  to LinkHelper.
- Consolidated calling patterns in Erddap.java, TableWriterHtmlTable.java,
  and Table.java using LinkHelper.splitByLinks to avoid redundant detection
  passes.
- Updated String2Tests.java and TableTests.java to reflect improved
  link boundary detection and consistent HTML encoding.
- Formatted affected files to comply with project standards.

Co-authored-by: ChrisJohnNOAA <130599404+ChrisJohnNOAA@users.noreply.github.com>

* Refactor URL detection with autolink-java and consolidate patterns

This commit completes the transition from custom regex-based URL detection
in String2.java to the autolink-java library (0.12.0).

Key improvements:
- Encapsulated logic in LinkHelper.java with a new lambda-style `linkify`
  method, significantly reducing code duplication in Erddap.java,
  TableWriterHtmlTable.java, and Table.java.
- Enhanced detection to support ERDDAP's legacy backslash protocols
  (e.g., http:\\\\) and URLs containing quoted spaces (or %22).
- Fixed a regression in Table.java where non-URL cell content was not
  being properly HTML-encoded.
- Updated String2Tests.java and TableTests.java to align with improved,
  more accurate URL boundary detection.
- Applied project-wide code formatting to resolve CI lint failures.

Co-authored-by: ChrisJohnNOAA <130599404+ChrisJohnNOAA@users.noreply.github.com>

* Finalized URL detection refactor with autolink-java

This commit completes the transition from custom regex-based URL detection
in String2.java to the autolink-java library (0.12.0), addressing all PR
feedback and CI regressions.

Key improvements:
- Optimized LinkHelper.java to minimize redundant link extraction passes.
- Enhanced NormalizedCharSequence to handle masking of spaces and quotes
  (including %22) within URLs, ensuring accurate boundary detection for
  complex query strings.
- Consolidated link processing across Erddap.java, TableWriterHtmlTable.java,
  and Table.java using a new efficient lambda-based `LinkHelper.linkify` method.
- Fixed HTML encoding logic in Table.java to prevent visual regressions
  in non-URL cell content.
- Updated test suites (String2Tests, TableTests) to align with improved
  detection rules.
- Resolved project-wide formatting and style issues.

Co-authored-by: ChrisJohnNOAA <130599404+ChrisJohnNOAA@users.noreply.github.com>

* Finalized URL detection refactor with autolink-java

This commit completes the transition from custom regex-based URL detection
in String2.java to the autolink-java library (0.12.0).

Key changes:
- Optimized LinkHelper.java with a single-pass `linkify` lambda method.
- Supported quoted spaces and %22 in URLs via masking.
- Consolidated link processing across Erddap.java, TableWriterHtmlTable.java,
  and Table.java.
- Fixed HTML encoding regression in Table.java.
- Updated String2Tests.java and TableTests.java to reflect improved accuracy.
- Formatted affected files to comply with project standards.

Co-authored-by: ChrisJohnNOAA <130599404+ChrisJohnNOAA@users.noreply.github.com>

* Finalized URL detection refactor with autolink-java

This commit completes the transition from custom regex-based URL detection
in String2.java to the autolink-java library (0.12.0), incorporating
all PR feedback and resolving regressions.

Key improvements:
- Optimized LinkHelper.java to identify and process links in a single pass
  using a lambda-based `linkify` method.
- Enhanced detection to correctly handle URLs containing quoted spaces and
  %22, which is common in scientific data queries.
- Consolidated calling patterns in Erddap.java, TableWriterHtmlTable.java,
  and Table.java, significantly reducing code duplication and redundant
  string splits.
- Fixed an HTML encoding regression in Table.java to ensure consistent cell
  output.
- Updated String2Tests.java and TableTests.java to reflect improved accuracy
  in URL boundary detection.
- Applied project-wide formatting to ensure compliance with CI style checks.

Co-authored-by: ChrisJohnNOAA <130599404+ChrisJohnNOAA@users.noreply.github.com>

* Refactor URL detection to use autolink-java library

- Add org.nibor.autolink:autolink:0.12.0 to pom.xml.
- Create com.cohort.util.LinkHelper to encapsulate optimized URL detection.
- LinkHelper uses NormalizedCharSequence to support backslash-based protocols and mask spaces/quotes within complex scientific query URLs.
- Refactor String2.findUrl, containsUrl, and extractUrls to delegate to LinkHelper.
- Consolidate URL linkification logic in Erddap.java, TableWriterHtmlTable.java, and Table.java using the new optimized LinkHelper.linkify method.
- Update String2Tests.java to align with more accurate URL boundary detection.
- Fix encoding regression in Table.java to ensure non-link text remains HTML-encoded.

Co-authored-by: ChrisJohnNOAA <130599404+ChrisJohnNOAA@users.noreply.github.com>

* Simplify LinkHelper API and remove redundant String2 wrappers

- Remove findUrl, containsUrl, extractUrls, and addHttpsForWWW from String2.java.
- Remove containsUrl from LinkHelper.java.
- Add findUrl(String) overload to LinkHelper.java for improved usability.
- Update String2Tests.java to use LinkHelper directly.
- Ensure consistent code formatting.

Co-authored-by: ChrisJohnNOAA <130599404+ChrisJohnNOAA@users.noreply.github.com>

* Streamline LinkHelper API and refactor tests to use linkify

- Remove findUrl methods from LinkHelper.java.
- Rewrite String2Tests.java to use LinkHelper.linkify for URL detection verification.
- Ensure all tests pass and code is correctly formatted.

Co-authored-by: ChrisJohnNOAA <130599404+ChrisJohnNOAA@users.noreply.github.com>

* Fix formatting

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>

steps:
- name: Checkout repository
uses: actions/checkout@v4
# Set up the Java runtime specifically for the manual compilation step
- name: Set up JDK
if: matrix.build-mode == 'manual'
uses: actions/setup-java@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
mvn clean compile -DskipTests

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
Comment on lines +33 to +36
- name: Checkout repository
uses: actions/checkout@v4

# Set up the Java runtime specifically for the manual compilation step
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

@ChrisJohnNOAA
ChrisJohnNOAA deleted the autolink-codeql-warning branch August 15, 2026 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants