Skip to content

Handle leading whitespace in BOM detection - #957

Merged
nscuro merged 1 commit into
CycloneDX:masterfrom
jdotc1:parser/leading-whitespace
Oct 18, 2026
Merged

nscuro merged 1 commit into
CycloneDX:masterfrom
jdotc1:parser/leading-whitespace

Conversation

@jdotc1

@jdotc1 jdotc1 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

The parser factory rejects valid JSON/XML documents when legal whitespace precedes their first content byte, including after a UTF-8 byte-order marker. File detection also stops after a four-byte prefix, so longer whitespace prefixes cannot be recognized.

Skip only space, tab, CR and LF during format detection, after the optional UTF-8 marker. Continue scanning files through a buffered stream when the initial prefix is whitespace, and reuse the same detection rules for byte arrays and the existing looksLikeCycloneDX heuristic. The original document is passed unchanged to the selected parser. No new dependency or public API is introduced.

Related downstream report: DependencyTrack/dependency-track#4983 . This addresses the parser-library gap; a released library update and downstream adoption are still required before claiming end-to-end Dependency-Track resolution.

Validation:

  • New cases demonstrated rejection of six whitespace-prefixed JSON/XML inputs on original production code.
  • mvn -B -q -Dtest=BomParserFactoryTest test passed after the change: 22 tests, 0 failures/errors/skips.
  • Cases exercise actual parsing through byte-array and file entry points, prefixes longer than the old four-byte sniff, UTF-8 markers, JSON recognition and empty/unsupported/non-JSON-whitespace rejection. Existing factory cases remain included.
  • git diff --check passed once.

JDK 25.0.3, Maven 3.9.16; production compilation retains the project's Java 8 release target. No full suite, CI Java-version matrix or downstream Dependency-Track import run was performed. Existing unrelated validation was reused without rerunning.

Accept legal whitespace before JSON and XML content when selecting a
parser. Keep file detection bounded in memory and preserve rejection of
empty or unsupported input.

Signed-off-by: jdotc1 <138259519+jdotc1@users.noreply.github.com>
@jdotc1
jdotc1 requested a review from a team as a code owner October 17, 2026 02:34
@codacy-production

codacy-production Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 11 complexity

Metric Results
Complexity 11

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.12% coverage variation

Metric Results
Coverage variation ✅ +0.12% coverage variation
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (2c410e3) 7872 5917 75.17%
Head commit (1a05bfb) 7883 (+11) 5935 (+18) 75.29% (+0.12%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#957) 18 18 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@nscuro nscuro added the bug Something isn't working label Oct 18, 2026
@nscuro
nscuro merged commit e0042b4 into CycloneDX:master Oct 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants