Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/main/java/org/perlonjava/parser/StringDoubleQuoted.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,13 @@ protected void parseEscapeSequence() {
}
inQuotemeta = false;
} else {
// Everything else is literal, including the backslash
currentSegment.append("\\");
// Everything else is literal, but \Q is ignored completely in quotemeta mode
if (!token.text.startsWith("Q")) {
// For anything other than \Q, append the backslash literally
currentSegment.append("\\");
}
// Always consume the character after the backslash
TokenUtils.consumeChar(parser);
}
return;
}
Expand Down Expand Up @@ -398,8 +403,12 @@ private void parseDoubleQuotedEscapesRegex() {
// Quotemeta modifier
case "Q" -> {
flushCurrentSegment();
inQuotemeta = true;
caseModifiers.push(new CaseModifier("Q", false));
// \Q is idempotent - don't nest multiple \Q sequences
if (!inQuotemeta) {
inQuotemeta = true;
caseModifiers.push(new CaseModifier("Q", false));
}
// If already in quotemeta mode, just ignore additional \Q
}

// Unknown escape - treat as literal character
Expand Down Expand Up @@ -479,8 +488,12 @@ private void parseDoubleQuotedEscapes() {
// Quotemeta modifier
case "Q" -> {
flushCurrentSegment();
inQuotemeta = true;
caseModifiers.push(new CaseModifier("Q", false));
// \Q is idempotent - don't nest multiple \Q sequences
if (!inQuotemeta) {
inQuotemeta = true;
caseModifiers.push(new CaseModifier("Q", false));
}
// If already in quotemeta mode, just ignore additional \Q
}

// Other escape sequences
Expand Down