fix: decode %3F back to "?" in toFileSystemPath (#427) - #428
Conversation
urlEncodePatterns encodes both # and ? when converting a filesystem path to a URL, but urlDecodePatterns only reversed #, $, &, ,, and @. A local path containing a literal ? (legal on POSIX filesystems) was encoded to %3F on the way in and never decoded back on the way out, so resolution of any such path failed with ENOENT. Adds the missing /%3F/g, "?" pair, in the same hex-ordered position the other pairs already follow. Adds a symmetric test for # alongside the new ? test.
|
Thanks for the fix — the intended literal- There is a double-decoding/path-aliasing regression: Because the new The new tests also fail in the live Windows Node and browser jobs. They use POSIX One smaller completeness issue: Suggested fix:
The focused and full suites pass locally on macOS, and I did not find a direct SSRF or path-traversal issue, but the wrong-file read and failing Windows checks should be fixed before merge. |
Problem
Fixes #427.
toFileSystemPathnever decodes%3Fback to?, so any$RefParsercall on a local path containing a literal?(a legal POSIX filename character) fails withResolverError: ENOENT. Confirmed onmainHEADe8190c1.Root cause
lib/util/url.tshas a matched pair of manual encode/decode tables for charactersencodeURI/decodeURIleave alone.urlEncodePatterns(line 13-16) encodes both?and#.urlDecodePatterns(line 19) only reverses#,$,&,,,@—?is missing, even though the comment directly above the decode loop names it explicitly ("This includes characters such as#and?...").Fix
Adds
/%3F/g, "?"tourlDecodePatterns, in the same hex-ordered position the other pairs follow. 1 line changed inlib/util/url.ts.How to test
Reproduced end-to-end too:
$RefParser.parse()on a local file named e.g.defs?1.jsonthrowsENOENTon unpatched code and resolves correctly with the fix.Backward compatibility
No breaking changes. Strictly adds a decode case that was previously a no-op (falling through unchanged); no existing behavior for any other character changes.
Assisted-by: Claude (code generation, reviewed and tested locally)