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 string literal misses single quotation marks in toStringAST() #29604

Closed
Pashulity opened this issue Nov 29, 2022 · 2 comments
Closed

SpEL string literal misses single quotation marks in toStringAST() #29604

Pashulity opened this issue Nov 29, 2022 · 2 comments
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

@Pashulity
Copy link

Pashulity commented Nov 29, 2022

Hi

Today I faced with the following problem: string literal loses single quotation marks after I call .toStringAST(). I implemented the test reproducing the bug:

var spelExpressionParser = new SpelExpressionParser();
var expression = (SpelExpression) spelExpressionParser.parseExpression("'123''1' == '123''1'");

assertEquals("'123''1' == '123''1'", expression.getAST().toStringAST());

And it fails with the error

expected: <'123''1' == '123''1'> but was: <('123'1' == '123'1')>

As far as I am concerned this occurs due to problems in StringLiteral class and toString() implementation which uses not original string but changed one after

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

in public constructor.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 29, 2022
@sbrannen sbrannen added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Nov 29, 2022
@sbrannen sbrannen removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 29, 2022
@sbrannen sbrannen added this to the 6.0.x milestone Nov 29, 2022
@sbrannen sbrannen self-assigned this Dec 3, 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 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