Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpEL: Two double quotes are replaced by one double quote in single quoted String literal (and vice versa) #28356

Closed
acc15 opened this issue Apr 18, 2022 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@acc15
Copy link

acc15 commented Apr 18, 2022

Affects: spring-expression since 3.2 M2 up to 5.3.19

The problem:
Two double quotes are replaced by one double quote - even when literal within single quotes

Expression Expected Actual
'keep "" two double quotes' keep "" two double quotes keep " two double quotes
"keep '' two single quotes" keep '' two single quotes keep ' two single quotes

According to reference guide only single quotes are allowed for String literals.

However double quotes are actually supported too (see #14254). And they also replacing two single quotes by one single quote.

valueWithinQuotes = StringUtils.replace(valueWithinQuotes, "\"\"", "\"");

Simple test program:

var p = new SpelExpressionParser();
System.out.println(p.parseExpression("'two double \"\" quotes'").getValue()); // prints two double " quotes
System.out.println(p.parseExpression("\"two single '' quotes\"").getValue()); // prints two single ' quotes
@acc15 acc15 changed the title SpEL: Two double quotes are replaced by one double quote in single quoted String literal SpEL: Two double quotes are replaced by one double quote in single quoted String literal (and vice versa) Apr 18, 2022
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 18, 2022
@sbrannen sbrannen added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 13, 2022
@sbrannen sbrannen added this to the 6.0.x milestone Nov 13, 2022
@sbrannen sbrannen self-assigned this Dec 7, 2022
@sbrannen sbrannen modified the milestones: 6.0.x, 6.0.3 Dec 7, 2022
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.3.x labels Dec 7, 2022
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Dec 7, 2022
Prior to this commit, there were two bugs in the support for quotes
within String literals in SpEL expressions.

- Two double quotes ("") or two single quotes ('') were always replaced
  with one double quote or one single quote, respectively, regardless
  of which quote character was used to enclose the original String
  literal. This resulted in the loss of one of the double quotes when
  the String literal was enclosed in single quotes, and vice versa. For
  example, 'x "" y' became 'x " y'.

- A single quote which was properly escaped in a String literal
  enclosed within single quotes was not escaped in the AST string
  representation of the expression. For example, 'x '' y' became 'x ' y'.

This commit fixes both of these related issues in StringLiteral and
overhauls the structure of ParsingTests.

Closes spring-projectsgh-29604, spring-projectsgh-28356
@sbrannen sbrannen closed this as completed Dec 7, 2022
sbrannen added a commit that referenced this issue Dec 7, 2022
Prior to this commit, there were two bugs in the support for quotes
within String literals in SpEL expressions.

- Two double quotes ("") or two single quotes ('') were always replaced
  with one double quote or one single quote, respectively, regardless
  of which quote character was used to enclose the original String
  literal. This resulted in the loss of one of the double quotes when
  the String literal was enclosed in single quotes, and vice versa. For
  example, 'x "" y' became 'x " y'.

- A single quote which was properly escaped in a String literal
  enclosed within single quotes was not escaped in the AST string
  representation of the expression. For example, 'x '' y' became 'x ' y'.

This commit fixes both of these related issues in StringLiteral and
overhauls the structure of ParsingTests.

Closes gh-29604
Closes gh-28356
@sbrannen
Copy link
Member

sbrannen commented Dec 7, 2022

This is has been fixed for Spring Framework 6.0.3 and backported to 5.3.25.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants