fix: preserve unrecognized escape sequences in string literals - #454
Open
chenjunwenhao wants to merge 1 commit into
Open
fix: preserve unrecognized escape sequences in string literals#454chenjunwenhao wants to merge 1 commit into
chenjunwenhao wants to merge 1 commit into
Conversation
…ba#335) QLStringUtils.parseStringEscapeStartEnd() silently dropped both the backslash and the following character for unrecognized escape sequences like \d, \w, \s. For example, '(\d*)ch' would become (*)ch instead of (\d*)ch, breaking regex patterns in string literals. Added a default case to the escape state switch that preserves the backslash and character as-is. Also added unit tests for QLStringUtils and extended the test suite with regex pattern escape tests. Documentation updated in both README-source.adoc and README-EN-source.adoc with a complete list of supported escape sequences.
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
QLStringUtils.parseStringEscapeStartEnd()silently drops both the backslash and the following character for unrecognized escape sequences like\d,\w,\s, etc.For example, the string literal
'(\d*)ch'produces(*)chinstead of(\d*)ch, which breaks regex patterns embedded in string literals (reported in #335).Root Cause
In
QLStringUtils.java, the escape state'sswitchstatement only handles recognized escape characters (b,t,n,f,r,",',\,$). There is nodefaultcase, so when an unrecognized character follows a backslash, neither the backslash nor the character is appended to the result.Fix
Added a
defaultcase to the escape state switch that preserves the backslash and the character as-is:This means:
\d→\d(preserved for regex use)\w→\w(preserved for regex use)\n→ newline (still works as before)\\→\(still works as before)Changes
QLStringUtils.java— Addeddefaultcase in escape state switchQLStringUtilsTest.java— New unit test class with 20+ test cases covering recognized, unrecognized, and mixed escape sequencesstring_escape.ql— Extended test suite with unrecognized escape and regex pattern testsREADME-source.adoc/README-EN-source.adoc— Added "String Escape Sequences" documentation section listing all supported escapesTesting
QLStringUtilscovering all recognized escapes, all common unrecognized escapes (\d,\w,\s,\D,\W,\S,\(,\.,\*,\+,\1), complex regex patterns, and mixed scenariosstring_escape.qltest suite with regex pattern assertions