Skip to content
Open
Show file tree
Hide file tree
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 = [
'\\-', '-',
'\\,', ',',
'\\<', '<',
'\\>', '>',
'\\{', '{',
'\\}', '}',
'\\[', '[',
'\\]', ']',
'\"', '"',
"\'", "'",
Comment on lines +41 to +42

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.

high

In JavaScript/TypeScript, the backslash in '\"' and "\'" acts as an escape character for the quote character itself within the string literal. Since double quotes do not need to be escaped inside single quotes (and vice versa), '\"' evaluates to " (length 1) and "\'" evaluates to ' (length 1).

As a result, the loop executes str.replaceAll('"', '"') and str.replaceAll("'", "'"), which does nothing and fails to unescape the actual backslash-escaped quotes (e.g., \" and \\') returned by Redis. This will cause JSON.parse to fail when parsing metadata containing quotes.

To fix this, escape the backslash itself so that the search strings are of length 2 (representing a literal backslash followed by a quote).

Suggested change
'\"', '"',
"\'", "'",
'\\"', '"',
"\\'", "'",

'\\:', ':',
'\\;', ';',
'\\!', '!',
'\\@', '@',
'\\#', '#',
'\\$', '$',
'\\%', '%',
'\\^', '^',
'\\&', '&',
'\\*', '*',
'\\(', '(',
'\\)', ')',
'\\+', '+',
'\\=', '=',
'\\~', '~',
]

for (let i = 0; i < specialChars.length; i += 2) {
str = str.replaceAll(specialChars[i], specialChars[i + 1])
}
return str
}
5 changes: 4 additions & 1 deletion packages/server/src/utils/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export class Telemetry {
postHog?: PostHog

constructor() {
if (process.env.POSTHOG_PUBLIC_API_KEY) {
// Respect DISABLE_FLOWISE_TELEMETRY env var / CLI flag for opt-out
if (process.env.DISABLE_FLOWISE_TELEMETRY === 'true' || process.env.DISABLE_FLOWISE_TELEMETRY === '1') {
this.postHog = undefined
} else if (process.env.POSTHOG_PUBLIC_API_KEY) {
this.postHog = new PostHog(process.env.POSTHOG_PUBLIC_API_KEY)
} else {
this.postHog = undefined
Expand Down