Repository navigation
Conversation
RediSearch reads unescaped ASCII punctuation in a TAG query as syntax. Characters such as '.', ',' and '/' split the value, so `source == 'report.pdf'` matched a document tagged "report pdf" and not the one tagged "report.pdf". Others such as ':', '@' and ';' made the query invalid, so filters on e-mail addresses, URLs or Windows paths failed. delete(filter) uses the same clause, so it removed the wrong documents or failed. Escape every ASCII character other than a letter, a digit or '_'. Non-ASCII characters are left as they are, since escaping them stops the value from matching. Fixes spring-projects#2945 Signed-off-by: Rohit Behera <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2945.
RedisFilterExpressionConverter.escapeTagValueescapes only\ $ | { } ( ) [ ] - ' *. RediSearch reads the rest of ASCII punctuation in a TAG query as syntax:.,,,/and similar characters split the value, and:,@,;and%make the query invalid.delete(filter)builds the same clause.On Redis Stack, with one document per
sourcevalue:source == 'report.pdf'report.pdfreport pdfdocumentdelete(source == 'report.pdf')report.pdfreport pdf, keepsreport.pdfdelete(source != 'report.pdf')report.pdfreport pdf, removesreport.pdfsource == 'v1.2-rc'v1.2-rcsource == '[email protected]'[email protected]JedisDataException: Syntax errorsource == 'https://example.com/a?b=1'JedisDataException: Syntax errorFile names are probably the most common case, since document readers put them in metadata.
The fix escapes every ASCII character other than a letter, a digit or
_. Non-ASCII characters are left as they are, because escaping them stops the value from matching. #3202 tried escaping.and\while parsing the filter text, which affects every store. This change stays in the Redis converter and also covers the builder API.Three existing converter tests asserted output that Redis rejects, for example
@description:{test@value\{with\}special\|chars}(syntax error at offset 8). I updated them.Tests:
RedisFilterExpressionConverterTests: the three updated expectations plustagValueEscapesPunctuationandtagValueKeepsLettersDigitsAndUnderscores. 4 fail without the fix.RedisVectorStoreTagFilterIT(new, Testcontainers only, no embedding provider needed): search and delete for 22 values with punctuation, plusINand a!=delete. 40 of 46 fail without the fix.RedisVectorStoreTagFilterIT46/46,RedisVectorStoreUpsertIT19/19 andRedisVectorStoreDistanceMetricIT3/3 pass. Checkstyle and spring-javaformat are clean.