Skip to content

Collapse the duplicated URL well-formedness scan into one exported primitive - #2357

Open
jakebromberg wants to merge 1 commit into
mainfrom
task/collapse-url-well-formedness-scan
Open

Collapse the duplicated URL well-formedness scan into one exported primitive#2357
jakebromberg wants to merge 1 commit into
mainfrom
task/collapse-url-well-formedness-scan

Conversation

@jakebromberg

Copy link
Copy Markdown
Member

Summary

shared/lml-client's safeHttpHostname and apps/backend/utils/album-metadata-projection.ts's hasWireUrlParserDifferential hand-maintained the same <= 0x20 || 0x7f || 0x5c character bar, just arranged differently (a two-step scan-then-backslash-check vs. a single-pass scan). apps/backend already depends on shared/lml-client (it imports isSpotifyUrl/isAppleMusicUrl from it), so the shared scan can live in shared/lml-client and be consumed by apps/backend without inverting the package graph.

  • Extracted the scan into shared/lml-client/src/streaming-url-guard.ts's newly exported hasUrlParserDifferentialChar, exported from shared/lml-client/src/index.ts.
  • safeHttpHostname now calls it instead of open-coding the two-step scan.
  • hasWireUrlParserDifferential keeps its exported name and doc comment, and now delegates to hasUrlParserDifferentialChar.
  • isSpotifyUrl/isAppleMusicUrl are untouched — they still go through safeHostname, not safeHttpHostname, so their characterization tests are unaffected.
  • wireUrl's trim semantics and safeHttpHostname's no-trim/lowercased-hostname behavior are both unchanged; only the scan itself moved.

Behavior-preserving by construction: the merged union of safeHttpHostname's two former steps is exactly hasWireUrlParserDifferential's single predicate, and both now literally call the same function.

Test plan

  • Added hasUrlParserDifferentialChar characterization tests in tests/unit/shared/lml-client/streaming-url-guard.test.ts
  • Added a dedicated hasWireUrlParserDifferential/wireUrl test file (tests/unit/utils/album-metadata-projection.wire-url.test.ts) pinning the delegation is behavior-preserving
  • npm run test:unit (525 suites / 9226 tests green)
  • npm run typecheck
  • npm run lint (no new errors; pre-existing warnings only)
  • npm run format:check

Closes #2356

…imitive

shared/lml-client's safeHttpHostname and apps/backend's hasWireUrlParserDifferential
hand-maintained the same <= 0x20 || 0x7f || 0x5c character bar in two arrangements.
apps/backend already depends on shared/lml-client, so the scan can live there without
inverting the package graph. Extract it as shared/lml-client's exported
hasUrlParserDifferentialChar; safeHttpHostname and hasWireUrlParserDifferential both
delegate to it, keeping their own names, doc comments, and surrounding
trim/no-trim behavior.

Closes #2356
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.

Collapse the duplicated URL well-formedness bar to one exported primitive

1 participant