Skip to content

Escaper does not escape the escapeCharacter itself #2182

@avdotius

Description

@avdotius
Escaper escaper = Escaper.DEFAULT;
String escaped = escaper.escape("a\\b%c");

will produce a string a\b\%c, where "%" is escaped but escape character itself is not escaped.

It leads to repository methods: "...StartsWith...", "...EndsWith...", "...Contains..." to return invalid results if search value contains escape character.

For the table:

id title
1 ab%cdef
2 a\b%cdef

running:

repository.findAllByTitleStartsWith("a\\b%c")

will generate:

Executing prepared SQL statement [... WHERE "entity"."title" LIKE ?]
Setting SQL statement parameter value: column index 1, parameter value [a\b\%c%], value class [java.lang.String], SQL type 12

and will return

id title
1 ab%cdef

Instead of:

id title
2 a\b%cdef

which is returned by the query ... WHERE "entity"."title" LIKE 'a\\b\%c%'

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions