fix: resolve backslash-escaped characters in .regexp string literals - #11
Merged
Conversation
Cherry-picked from Mearman/cddl's fix/string-literal-escape-sequences (tracking webdriverio/cddl#91/#92): readString() sliced a text-string literal's raw source between its two quotes with no RFC 8610 SESC escape processing at all, so a backslash written to escape another character (a quote, or itself) stayed in the token's Literal verbatim. A .regexp rule needing an escaped backslash therefore parsed with an extra literal backslash still attached, which the emitter then re-embedded into a generated RegExp source string, double-escaping it and silently changing what the pattern matches.
…itted RegExp Pins two cases through the real parse -> emitModule -> generated-schema pipeline: a synthetic DM-room-path-style rule pairing two hex components with an escaped literal plus, and wire-mesh's real namespaced-domain-id rule, which has carried the double-escaping bug since before this project existed.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
3 tasks
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.
The vendored parser's readString() sliced a text-string literal's raw source between its two quotes with no RFC 8610 SESC escape processing at all, so a backslash written to escape another character (a quote, or itself) stayed in the token's Literal verbatim instead of being consumed. A .regexp rule needing an escaped backslash (
\\.,\\+) therefore parsed with an extra literal backslash still attached, which the emitter then re-embedded into a generatednew RegExp(...)call, double-escaping it and silently changing what the pattern matches.Found generating wire-mesh's new
dm-room-pathrule ([0-9a-f]{64}\\+[0-9a-f]{64}) — confirmed the same bug already affects the already-shippednamespacedDomainIdSchematoo, sincenamespaced-domain-id's own pattern has the identical escaped-dot shape.Fixed upstream first per this project's own foundation decision (docs/0001-foundation.md): webdriverio/cddl#91 / webdriverio/cddl#92, cherry-picked into the vendored fork here in the meantime.
Test plan
pnpm build && pnpm test && pnpm lint && pnpm typecheck— all greennamespaced-domain-idrule through parse → emitModule → generated schema → safeParse