Skip to content

fix: address SonarQube findings - #14

Merged
fabianzimber merged 1 commit into
mainfrom
fix/sonar-findings
Nov 27, 2026
Merged

fabianzimber merged 1 commit into
mainfrom
fix/sonar-findings

Conversation

@fabianzimber

@fabianzimber fabianzimber commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

What

  • Request path trimming in linear time. The router stripped trailing slashes with replace(/\/+$/, ""), which backtracks quadratically on a long run of slashes not at the end (a 16 KB path cost ~200 ms CPU). New trimTrailingSlashes helper in util.ts, also used for the publisher URL in the JSON-LD.
  • Fire-and-forget PostHog calls marked with void. phCapture/phException hand the send to ctx.waitUntil; the returned promise is intentionally not awaited. No behaviour change.
  • TypeScript detection regex: the ^ anchored alternative is grouped explicitly. Same matching behaviour.
  • CI: npm ci --ignore-scripts (no dependency needs install scripts; typecheck, tests and build pass without them).

The remaining backtracking warnings on the language detection signals in highlight.ts are left as they are: they only run on a sample capped at 4 KB with lines of at most 300 characters (worst adversarial input measured at under 4 ms).

How to test

npm ci --ignore-scripts; npm run check

New unit tests cover trimTrailingSlashes, including a 100k-slash input.

- trim trailing slashes in linear time; the /\/+$/ replace on the request
  path backtracked quadratically on long runs of slashes
- mark fire-and-forget PostHog calls with void
- group the anchored TypeScript detection alternative explicitly
- install CI dependencies with --ignore-scripts
@sonarqubecloud

Copy link
Copy Markdown

@fabianzimber
fabianzimber merged commit ab21bfe into main Nov 27, 2026
7 checks passed
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.

1 participant