fix(schema): escape path.sep before use in RegExp character class on Windows#4
Open
LunarLaurus wants to merge 1 commit into
Open
fix(schema): escape path.sep before use in RegExp character class on Windows#4LunarLaurus wants to merge 1 commit into
LunarLaurus wants to merge 1 commit into
Conversation
…Windows On Windows, path.sep is '\'. When interpolated directly into a RegExp character class as [^\], the backslash escapes the closing bracket, leaving the class unterminated and throwing a SyntaxError at startup. Escape the separator before building the RegExp so it works on both platforms: path.sep.replace(/\/g, '\\') produces '\' on Windows (matching a literal backslash in the pattern) and is a no-op on POSIX.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Windows,
path.sepis\(backslash). When interpolated directly into aRegExpcharacter class:the string passed to
RegExpon Windows becomes:Inside the character class,
\]is interpreted as an escaped](a literal]character), so the class[^never closes — Node throwsSyntaxError: Invalid regular expression … Unterminated character classat the pointschema.jsis first required, which crashes any command that invokes the validator on Windows.Fix
Escape the separator before building the
RegExp, so it is safe in both the character class and the surrounding pattern on all platforms:path.sep = '\'→sep = '\'→ regex pattern[^\](not a backslash) ✅path.sep = '/'→sep = '/'(no-op) → regex pattern[^/]✅Testing
Validated against
Notes/*.mdbelief files on Windows 10 schema validator now returns clean JSON without crashing.