Skip to content

Decode escaped backslashes in raw string literals - #385

Open
blouirts123 wants to merge 1 commit into
jmespath:developfrom
blouirts123:fix/raw-string-backslash-escape
Open

blouirts123 wants to merge 1 commit into
jmespath:developfrom
blouirts123:fix/raw-string-backslash-escape

Conversation

@blouirts123

@blouirts123 blouirts123 commented Oct 16, 2026 •

Copy link
Copy Markdown

Raw strings currently retain both backslashes in an escaped backslash, so a filter looking for a Windows path segment ending in \ can match the wrong rows. Decode the two raw-string escape forms in one pass, preserving unknown escapes such as \z and \u.

This follows the current specification's raw-string grammar. The existing compliance case is updated to that grammar; the older JEP-12 page uses different wording. Related to #323.

Validation: full suites on Python 3.12 and 3.14: 995 passed, 1 skipped; independent compliance/focused run: 924 passed; root focused tests: 4 passed. Existing deprecation warnings remain.

Adjacent #349 adds lexer unit coverage without implementing this decoding; #382 fixes token offsets, which this change leaves untouched.

@blouirts123
blouirts123 marked this pull request as draft October 16, 2026 04:51
@blouirts123
blouirts123 marked this pull request as ready for review October 16, 2026 05:24
@carlitogwapito

Copy link
Copy Markdown

Small companion for adjacent escapes: 20-line test-only commit, based on this branch with no implementation changes.

Two useful guards: an escaped backslash beside an escaped quote, and an escaped backslash beside a preserved \u1234 sequence. The latter should remain literal rather than becoming a Unicode character or losing another backslash. These compose the two escape forms in the current grammar, instead of testing them only in isolation.

Both new test methods pass against this branch's complete package source on Windows/Python 3.14.4, checking lexer values and public search. The base fails both at the lexer assertion, and a separate check confirms search returns the wrong value too. The existing unknown-escape and escaped-quote controls pass on both sources, with fresh package/parser state for each case.

Focused Ruff lint/format checks pass. I haven't run the full suite or version matrix, and these don't address the separate token-offset work. With the file added to this branch, the command is python -m unittest tests.test_raw_string_escape_composition. Take whichever cases help.

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.

2 participants