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

Trim BindableMongoExpression input to better support text blocks #4821

Open
gbaso opened this issue Oct 25, 2024 · 1 comment · May be fixed by #4822
Open

Trim BindableMongoExpression input to better support text blocks #4821

gbaso opened this issue Oct 25, 2024 · 1 comment · May be fixed by #4822
Labels
type: enhancement A general enhancement

Comments

@gbaso
Copy link

gbaso commented Oct 25, 2024

BindableMongoExpression#wrapJsonIfNecessary detects if the input expression already contains the opening and closing braces, and if not they are added. This is useful for one-liners, but it doesn't work as well in other situations.

When using text blocks, it is common to put the closing delimiter on a new line (see the examples in JEP 378 and various tests in this repository), which means the last character of the string will be a line terminator. BindableMongoExpression checks only the last character for }, and if it doesn't match the whole expression is wrapped as { + json + }.

This results in the following:

MongoExpression.create("""
    {
      $toUpper: $last_name
    }
    """);

to be parsed as:

{{
  $toUpper: $last_name
}
}

which is obviously not a valid json. Trimming could be applied to the input expression to avoid this problem.

If the issue is accepted, I can submit a PR.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 25, 2024
@christophstrobl
Copy link
Member

Thank you for bringing this to our attention. If you have time to work on a PR we're happy to help with that. Please make sure to follow our Contribution Guidelines.

@christophstrobl christophstrobl added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 28, 2024
@gbaso gbaso linked a pull request Oct 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants