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

Closed
gbaso opened this issue Oct 25, 2024 · 1 comment
Closed

Trim BindableMongoExpression input to better support text blocks #4821

gbaso opened this issue Oct 25, 2024 · 1 comment
Assignees
Labels
type: enhancement A general enhancement

Comments

@gbaso
Copy link
Contributor

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
@christophstrobl christophstrobl self-assigned this Dec 9, 2024
christophstrobl pushed a commit that referenced this issue Jan 16, 2025
Trim the given source so that wrapping checks still work for text blocks.
Fix a typo in Javadoc.

Resolves: #4821
Original Pull Request: #4822
@christophstrobl christophstrobl added this to the 4.4.2 (2024.1.2) milestone Jan 16, 2025
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