Skip to content

fix: unEscapeSpecialChars handles all RediSearch special characters#6636

Open
zzhzhangzhihao wants to merge 1 commit into
FlowiseAI:mainfrom
zzhzhangzhihao:fix/redis-unescapespecialchars-special-chars
Open

fix: unEscapeSpecialChars handles all RediSearch special characters#6636
zzhzhangzhihao wants to merge 1 commit into
FlowiseAI:mainfrom
zzhzhangzhihao:fix/redis-unescapespecialchars-special-chars

Conversation

@zzhzhangzhihao

Copy link
Copy Markdown

What

Fixes unEscapeSpecialChars in Redis vector store utility to handle all RediSearch special characters, not just -.

Why

Previously, unEscapeSpecialChars only unescaped the - character. When document metadata contained other RediSearch reserved characters (: " , . < > { } [ ] ; ! @ # $ % ^ & * ( ) - + = ~), the JSON parsing of metadata would fail with errors like:

Expected property name or '}' in JSON at position 1

This affected any document whose metadata contained these special characters.

Fix

Updated unEscapeSpecialChars in packages/components/nodes/vectorstores/Redis/utils.ts to iterate over all RediSearch special characters and unescape them, matching the full set of reserved characters documented at https://redis.io/docs/latest/develop/interact/search-and-query/advanced/concepts/special-characters/

Related

- Previously only escaped/unescaped '-' character
- Now handles all RediSearch reserved characters: , . < > { } [ ] " ' : ; ! @ # $ % ^ & * ( ) - + = ~
- Fixes JSON.parse failure when metadata contains special characters (FlowiseAI#6598)

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the unEscapeSpecialChars function in the Redis vector store utilities to handle a comprehensive list of RediSearch special characters. The reviewer noted that the dot (.) and pipe (|) characters are missing from this list, which could lead to failures during JSON.parse if they remain escaped, and provided a suggestion to include them.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +30 to +63
// RediSearch special characters that need to be unescaped
// https://redis.io/docs/latest/develop/interact/search-and-query/advanced/concepts/special-characters/
const specialChars = [
'\\-', '-',
'\\,', ',',
'\\<', '<',
'\\>', '>',
'\\{', '{',
'\\}', '}',
'\\[', '[',
'\\]', ']',
'\"', '"',
"\'", "'",
'\\:', ':',
'\\;', ';',
'\\!', '!',
'\\@', '@',
'\\#', '#',
'\\$', '$',
'\\%', '%',
'\\^', '^',
'\\&', '&',
'\\*', '*',
'\\(', '(',
'\\)', ')',
'\\+', '+',
'\\=', '=',
'\\~', '~',
]

for (let i = 0; i < specialChars.length; i += 2) {
str = str.replaceAll(specialChars[i], specialChars[i + 1])
}
return str

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Missing Special Characters

The implementation is missing . (dot) and | (pipe), which are official RediSearch reserved characters (as documented in the Redis Special Characters documentation). If metadata contains these characters, they will remain escaped, causing JSON.parse to fail.

Recommended Solution

Add unescaping for . and | to the existing chain of replacements. To maintain code readability and understandability, we should prefer a series of simple, chained operations over a single complex regular expression, as it reduces the potential for future errors.

Suggested change
// RediSearch special characters that need to be unescaped
// https://redis.io/docs/latest/develop/interact/search-and-query/advanced/concepts/special-characters/
const specialChars = [
'\\-', '-',
'\\,', ',',
'\\<', '<',
'\\>', '>',
'\\{', '{',
'\\}', '}',
'\\[', '[',
'\\]', ']',
'\"', '"',
"\'", "'",
'\\:', ':',
'\\;', ';',
'\\!', '!',
'\\@', '@',
'\\#', '#',
'\\$', '$',
'\\%', '%',
'\\^', '^',
'\\&', '&',
'\\*', '*',
'\\(', '(',
'\\)', ')',
'\\+', '+',
'\\=', '=',
'\\~', '~',
]
for (let i = 0; i < specialChars.length; i += 2) {
str = str.replaceAll(specialChars[i], specialChars[i + 1])
}
return str
str.replaceAll('\\.', '.').replaceAll('\\|', '|')
References
  1. Prioritize code readability and understandability over conciseness. A series of simple, chained operations can be preferable to a single, more complex one (e.g., a complex regex with a replacer function) if it improves understandability and reduces the potential for future errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redis vector store: unEscapeSpecialChars only reverses -, causing JSON.parse failure on metadata read

1 participant