Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion packages/components/nodes/vectorstores/Redis/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,38 @@ export const escapeAllStrings = (obj: object) => {
}

export const unEscapeSpecialChars = (str: string) => {
return str.replaceAll('\\-', '-')
// 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
Comment on lines +30 to +63

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.

}