Skip to content

Trim BindableMongoExpression input to better support text blocks #4821

Closed
@gbaso

Description

@gbaso

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions