Skip to content

refactor(github): carry the bearer shape's case-insensitivity as a compile flag - #754

Merged
devops-thiago merged 1 commit into
mainfrom
chore/unwrap-bearer-case-flag
Aug 16, 2026
Merged

refactor(github): carry the bearer shape's case-insensitivity as a compile flag#754
devops-thiago merged 1 commit into
mainfrom
chore/unwrap-bearer-case-flag

Conversation

@devops-thiago

@devops-thiago devops-thiago commented Aug 16, 2026

Copy link
Copy Markdown
Owner

What type of PR is this?

  • ♻️ Refactor

Description

#750 split CREDENTIAL_SHAPED_VALUE into BEARER_SHAPED_VALUE and JWT_SHAPED_VALUE to get the combined pattern's complexity back under budget. That split left one loose end, which the analysis on that PR flagged and which merged with it:

java:S6395 | MAJOR | GitHubApiError.java:134 | Unwrap this unnecessarily grouped subpattern.

The rule is right. (?i:bearer\s+[\w.~+/=-]{4,}) existed to scope case-insensitivity to the bearer alternative of a two-alternative pattern — that scoping was #746's fix, and it is why eyjafjallajokull.internal.example.com stopped coming out as ***.com. Once the alternation was gone there was nothing left to scope the flag away from, so the group wraps the entire pattern and does nothing.

The flag moves to the compile call:

Pattern.compile("bearer\\s+[\\w.~+/=-]{4,}", Pattern.CASE_INSENSITIVE)

Behaviour is identical, and the identity matters. Pattern.CASE_INSENSITIVE without UNICODE_CASE matches ASCII case only — exactly what (?i:...) did. That is the correct scope here: the shape is matching the literal HTTP Bearer auth-scheme token, not prose, so Unicode case folding would only widen what a log line masks. The javadoc now records it, so the ASCII scope reads as the decision it is rather than as something to "fix" by adding UNICODE_CASE.

JWT_SHAPED_VALUE stays case-sensitive, unchanged.

Related Issues

Follow-up to #750; no separate issue filed, since the finding arrived through the analysis on that PR and is a two-line correction to it.

How Has This Been Tested?

  • Unit tests

No new test, and deliberately so: this is a refactor with no behavioural delta, so there is no red state to demonstrate. A test written for it would pass before the change as well, which proves nothing.

The existing coverage is what pins the equivalence, and two tests in GitHubApiErrorTest bear directly on it:

  • masksABearerHeaderWhateverCaseItArrivedIn — the case-insensitivity survives the move off the inline group
  • doesNotMaskOrdinaryTextThatMerelyBeginsLikeAJwtHeaderInSomeOtherCase — the JWT shape stays case-sensitive, i.e. the flag did not leak across the split

Both are controls: green before and after.

Gates

  • ./mvnw -B spotless:apply → clean
  • ./mvnw -B clean compile spotbugs:check spotless:checkBugInstance size is 0, BUILD SUCCESS
  • ./mvnw -B clean testTests run: 3324, Failures: 0, Errors: 0, Skipped: 0
  • jacoco ∩ git diff -U0 HEAD on changed main code → one executable line changed (the Pattern.compile call), zero uncovered lines, zero uncovered branches

Checklist

  • My code follows the project's coding standards
  • I have performed a self-review of my own code
  • 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
  • I have updated the documentation accordingly
  • My changes generate no new warnings or errors

Additional Notes

The rest of the diff is javadoc. The block above BEARER_SHAPED_VALUE still opened by calling itself "the bearer and JWT shapes", which was accurate while it documented one field and stopped being so when the split made two. It now says which shape each paragraph is about and why the two are documented together.

…mpile flag

Splitting the value shapes into one pattern each left `(?i:...)` wrapping
the whole of the bearer pattern, which is a group that does nothing: with
no second alternative to scope it away from, the flag applies to the
pattern either way.

Moving it to `Pattern.CASE_INSENSITIVE` keeps the behaviour exactly —
without `UNICODE_CASE` the flag is ASCII-only, which is what the inline
group was — and the javadoc now says so, so the ASCII scope is not read
as an oversight and widened later.

Also adjusts the wording for readability: the javadoc still opened by
naming itself the bearer and JWT shapes, which stopped being true when
the two became separate fields.
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@thrillhousebot

Copy link
Copy Markdown
Contributor

🤖 ThrillhouseBot PR Summary

What this PR does

Refactors BEARER_SHAPED_VALUE in GitHubApiError so case-insensitive matching is applied via Pattern.compile(..., Pattern.CASE_INSENSITIVE) instead of an inline (?i:...) group, and rewrites the surrounding javadoc to document the bearer/JWT shape split, the ASCII-only case-folding scope, and why the JWT shape stays case-sensitive. No behavioral change is intended or produced.

Description vs. Implementation

No mismatch found between the PR description and the change.

Changes Overview

  • Files changed: 1
  • Lines added: +20
  • Lines removed: -16

Changed Files

File Change Summary
src/main/java/dev/thiagogonzaga/thrillhousebot/github/GitHubApiError.java Modified Moves BEARER_SHAPED_VALUE's case-insensitivity to the Pattern.compile flags and rewrites the javadoc for the bearer/JWT split.

Risk Assessment

Risk Count
🔴 Critical 0
🟠 High 0
🟡 Medium 0
🔵 Low 0

No new issues found in this PR, but the review cannot be approved until required CI is confirmed green.

⚠️ Required CI Checks Status

Some required checks are still pending or have failed:

Check Type Status Detail
test check-run ⏳ Pending -
trivy check-run ⏳ Pending -
frontend check-run ⏳ Pending -
format check-run ⏳ Pending -
dependency-review check-run ⏳ Pending -

Automated review by ThrillhouseBot. Reply with /review to re-run.

@thrillhousebot thrillhousebot Bot added java Pull requests that update java code tech-debt labels Aug 16, 2026
@codecov

codecov Bot commented Aug 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sonarqubecloud

Copy link
Copy Markdown

@devops-thiago
devops-thiago merged commit 73cc33d into main Aug 16, 2026
17 checks passed
@devops-thiago
devops-thiago deleted the chore/unwrap-bearer-case-flag branch August 16, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

java Pull requests that update java code tech-debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant