Skip to content

Commit 3abe53f

Browse files
icecrasher321claude
andcommitted
fix(file): close the allowlist around PostgreSQL bracket expressions
`[:class:]` was rejected while `[=equivalence=]` and `[.collating.]` were forwarded unchanged. All three are PostgreSQL bracket expressions with no JavaScript counterpart, and the parser exists to admit only what both engines spell the same way — so two of them passed an allowlist whose whole point is to close, and were accepted by documentation that says POSIX classes are not supported. They are now rejected by the construct they open, each named in its own error. An ordinary class holding a literal dot, `[.]` or `[a.b]`, is untouched: the form only matches on a bracket nested inside a class. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 6a77a8f commit 3abe53f

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

apps/sim/lib/workspace-files/search/regex.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ describe('analyzeFileSearchRegex', () => {
9090
['(?<name>foo)', /Named group/],
9191
['(?i)foo', /Inline flag/],
9292
['(foo)\\1bar', /Backreference/],
93-
['[[:alpha:]]foo', /POSIX class/],
93+
['[[:alpha:]]foo', /POSIX character class/],
94+
['[[=a=]]foo', /POSIX equivalence class/],
95+
['[[.hyphen.]]foo', /POSIX collating element/],
9496
['\\p{Lu}foo', /Unicode property/],
9597
['\\yfoo\\y', /"\\y" is not supported write "\\b" instead/],
9698
['\\Afoo\\Z', /"\\A" is not supported write "\^" instead/],
@@ -132,6 +134,8 @@ describe('analyzeFileSearchRegex', () => {
132134
'user_id=\\w+ token',
133135
'error a{3,}bcd',
134136
'error a{3,10}bcd',
137+
'needle[.]txt',
138+
'needle[a.b]txt',
135139
])('accepts %s', (source) => {
136140
expect(() => analyzeFileSearchRegex(source)).not.toThrow()
137141
})

apps/sim/lib/workspace-files/search/regex.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ const OPAQUE: LiteralGuarantee = {
6262
zeroWidth: false,
6363
}
6464

65+
/** PostgreSQL bracket expressions, by the character that opens them after `[`. */
66+
const POSIX_BRACKETS: Record<string, string | undefined> = {
67+
':': 'character class',
68+
'=': 'equivalence class',
69+
'.': 'collating element',
70+
}
71+
6572
/** Escapes whose meaning and spelling are identical in PostgreSQL ARE and JavaScript. */
6673
const SHARED_ESCAPE_LETTERS = new Set(['d', 'D', 'w', 'W', 's', 'S', 't', 'n', 'r', 'f', 'v'])
6774

@@ -401,9 +408,17 @@ class FileSearchRegexParser {
401408
this.index += 1
402409
return OPAQUE
403410
}
404-
if (character === '[' && this.source[this.index + 1] === ':') {
411+
/**
412+
* `[:class:]`, `[=equivalence=]` and `[.collating.]` are all PostgreSQL
413+
* bracket expressions with no JavaScript counterpart — JavaScript reads
414+
* them as an ordinary set of characters. Only the first was rejected, so
415+
* the other two passed an allowlist whose whole point is to close.
416+
*/
417+
const posixBracket =
418+
character === '[' ? POSIX_BRACKETS[this.source[this.index + 1]] : undefined
419+
if (posixBracket) {
405420
throw new FileSearchPatternError(
406-
`POSIX class at position ${this.index + 1} is not supported — write the range directly, such as "[a-z]" or "\\w"`
421+
`POSIX ${posixBracket} at position ${this.index + 1} is not supported — write the characters directly, such as "[a-z]" or "\\w"`
407422
)
408423
}
409424
if (character === '\\') {

0 commit comments

Comments
 (0)