Skip to content

fix(plugins): keep the query string intact in dedupeSlashes - #2027

Open
goranai wants to merge 1 commit into
restify:masterfrom
goranai:fix/dedupe-slashes-query
Open

goranai wants to merge 1 commit into
restify:masterfrom
goranai:fix/dedupe-slashes-query

Conversation

@goranai

@goranai goranai commented Nov 17, 2026

Copy link
Copy Markdown

Pre-Submission Checklist

  • Opened an issue discussing these changes before opening the PR
  • Ran the linter and tests (the eslint, nodeunit and mocha steps of make prepush, run one by one on Windows)
  • Included comprehensive and convincing tests for changes

Issues

Closes:

pre.dedupeSlashes() ran its regex over the whole req.url. So // inside the query string was collapsed too, and ?next=http://example.com/home reached the handler as http:/example.com/home.

Changes

  • lib/plugins/pre/dedupeSlashes.js: split req.url at the first ? or #. Duplicate slashes are removed from the path only. The rest is appended back unchanged.
  • test/plugins/dedupeSlashes.test.js: two new tests. One checks that //foo//bar//?next=http://example.com//x becomes /foo/bar/?next=http://example.com//x. One checks that an empty query (//foo//bar//?) is kept as /foo/bar/?.

Behavior change: the path is cleaned exactly as before, so routing does not change. Anything from the first ? or # on is now left byte for byte. A request like //foo?a=//b used to reach the handler as /foo?a=/b and now reaches it as /foo?a=//b. A raw # fragment (clients do not normally send one) is also left as is.

pre.sanitizePath() has the same problem with the query string. I did not touch it here because PR #1960 is open on that file.

Testing

On Windows 11 with Node 24.19.0:

  • mocha test/plugins/dedupeSlashes.test.js test/plugins/query.test.js: 16 passing.
  • With the lib change reverted and the new tests kept, mocha test/plugins/dedupeSlashes.test.js gives 4 passing, 1 failing (expected '/foo/bar/?next=http:/example.com/x' to equal '/foo/bar/?next=http://example.com//x').
  • mocha test/plugins/*.test.js: 199 passing, 20 failing. Without this change it is 197 passing and the same 20 failing (staticFiles and cpuUsageThrottle, which fail on my Windows machine).
  • nodeunit test/*.test.js: 1/897 assertions failed (listen and close (socketPath), a Unix socket test that fails on Windows).
  • make check-lint and make check-style (eslint over the repo): 0 errors.
  • I also ran a 300000 case random comparison of the plugin against a small reference (dedupe the path, keep the rest). Master was wrong on 9362 inputs and this change on 0. The path part was the same as master on every input.

Validated with Claude Opus 5.5.

This branch has not been deployed

No deployments
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