Skip to content

fix(redis): escape all RediSearch special chars in metadata, not just -#6610

Open
iruzen-dono wants to merge 1 commit into
FlowiseAI:mainfrom
iruzen-dono:fix/redis-escape-all-special-chars
Open

fix(redis): escape all RediSearch special chars in metadata, not just -#6610
iruzen-dono wants to merge 1 commit into
FlowiseAI:mainfrom
iruzen-dono:fix/redis-escape-all-special-chars

Conversation

@iruzen-dono

Copy link
Copy Markdown

What

Redis vector store escapeSpecialChars only escapes the - character, but Redis Search reserves many more characters as operators/syntax: ,.<>{}[]"':;!@#$%^&*()-+=~

When document metadata contains any of these unescaped characters (e.g. :, "), JSON.parse fails on retrieval.

Fix

  • escapeSpecialChars: now escapes all 26 RediSearch reserved characters
  • unEscapeSpecialChars: now reverses all 26 escaped characters (single regex)

Reproduction

  1. Setup Redis vector store node
  2. Upsert document with metadata containing colon or double quote
  3. Run similarity search in Playground → JSON error
  4. After fix: works

References

Closes #6598

Redis Search reserves many characters as operators/syntax:
,.<>{}[]"':;!@#$%^&*()-+=~

The current escapeSpecialChars only escapes '-', so metadata containing
any other special character (e.g. ':', '"') causes JSON.parse failures
when retrieved from the vector store.

Fix by escaping all reserved characters on write and un-escaping them
on read.

Fixes FlowiseAI#6598
Copilot AI review requested due to automatic review settings July 11, 2026 00:57

@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 expands the Redis utility functions to escape and unescape a comprehensive list of RediSearch special characters, rather than just the hyphen. The review feedback correctly identifies a redundant hyphen in the regular expression used for unescaping and provides a cleaner regex suggestion.

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.


export const unEscapeSpecialChars = (str: string) => {
return str.replaceAll('\\-', '-')
return str.replace(/\\([-,.<>{}[\]"':;!@#$%^&*()\-+=~])/g, '$1')

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

The character class contains a redundant escaped hyphen \- in addition to the leading hyphen -. We can simplify the regex by removing the redundant hyphen.

Suggested change
return str.replace(/\\([-,.<>{}[\]"':;!@#$%^&*()\-+=~])/g, '$1')
return str.replace(/\\([-,.<>{}[\]"':;!@#$%^&*()+=~])/g, '$1')

Copilot AI 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.

Pull request overview

This PR fixes Redis vector store metadata retrieval failures by expanding RediSearch escaping/unescaping beyond just -, so metadata containing other reserved characters (e.g. : or ") can be safely round-tripped and parsed as JSON.

Changes:

  • Expand escapeSpecialChars to escape the full RediSearch reserved character set used by queries/tag values.
  • Update unEscapeSpecialChars to reverse all escaped reserved characters via a single regex.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 54 to 56
export const unEscapeSpecialChars = (str: string) => {
return str.replaceAll('\\-', '-')
return str.replace(/\\([-,.<>{}[\]"':;!@#$%^&*()\-+=~])/g, '$1')
}
.replaceAll(')', '\\)')
.replaceAll('+', '\\+')
.replaceAll('=', '\\=')
.replaceAll('~', '\\~')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good catch. I think we’re still missing one Redis query separator: |.

Since buildQuery uses | as the OR operator to join metadata filters, a literal value like foo | bar will be incorrectly parsed as two separate alternatives instead of a single metadata value. As noted in the Redis documentation, | is a special character that needs to be escaped in tag filters.

Could you, please, update both escapeSpecialChars and unEscapeSpecialChars to include |, and add a regression test for a metadata filter value containing a pipe? I think it'll be really useful!

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

3 participants