Skip to content

fix(utils): make normalizePath idempotent by globally collapsing repeated slashes - #163

Open
2503piglu wants to merge 2 commits into
tscircuit:mainfrom
2503piglu:fix/normalize-path-idempotent
Open

2503piglu wants to merge 2 commits into
tscircuit:mainfrom
2503piglu:fix/normalize-path-idempotent

Conversation

@2503piglu

Copy link
Copy Markdown

Summary

Fixes #161.

normalizePath in lib/utils/normalize-path.ts only collapsed the first run of repeated slashes because the regex /\/\/+/ was missing the global (g) flag. Paths like a///b///c.txt came out as a/b///c.txt, so the function was not idempotent.

Change

Add the g flag: .replace(/\/\/+/g, "/"). Also add tests/utils/normalize-path.test.ts covering repeated slashes, idempotency, backslashes, and leading/trailing/root slashes.

Add tests for normalizePath function covering various cases.
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.

normalizePath is not idempotent when a path has multiple repeated slash groups

1 participant