Skip to content

fix: make normalizePath fully idempotent (collapse all repeated slash groups) - #170

Open
Lion0871 wants to merge 2 commits into
tscircuit:mainfrom
Lion0871:fix-normalize-path-idempotent
Open

Lion0871 wants to merge 2 commits into
tscircuit:mainfrom
Lion0871:fix-normalize-path-idempotent

Conversation

@Lion0871

Copy link
Copy Markdown

/claim #5

Following the /attempt #5 plan. The download endpoints (query form + path form) already exist on main; the remaining defect that breaks reliable downloads is normalizePath missing the global flag on its slash-collapse regex, so repeated slash groups beyond the first survive and the function is not idempotent — route-joined path segments then fail to match stored files.

Changes:

  • fix regex to collapse every repeated slash group (global flag), keeping it idempotent
  • add tests/routes/download.test.ts covering issue Create download endpoint /files/download?... as well as /files/download/[[file_path]] #5 deliverables: normalizePath idempotence (incl. 4+ slash groups), query-form text download with Content-Disposition, path-form deep download, binary bytes exactness + Content-Length + octet-stream, 404 body for unknown file, path-form matching with leading-slash storage
  • full suite locally: 35 pass / 0 fail (bun test, bun 1.4.4, Node-compatible fetch probe)

… groups)

normalizePath used /\/\/+/ (single match per pass) so '///a//b' normalized to
'/ /a/b'-style leftovers and was not idempotent; path-form download routes joined
route segments and then relied on getFile's normalizePath, so requests with
repeated slashes missed stored files. Use /\/\/+/g globally and add download
endpoint tests (query form, path form, binary bytes/content-length, 404,
idempotence) covering issue tscircuit#5 deliverables.
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