:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(insights): validate each value of a multi-value regex filter (#93586)
Kim Svatos Dugan5055c43ab707
diff --git a/frontend/src/lib/components/PropertyFilters/components/OperatorValueSelect.test.tsx b/frontend/src/lib/components/PropertyFilters/components/OperatorValueSelect.test.tsxnew file mode 100644index 000000000000..4e3ff6743dae--- /dev/null+++ b/frontend/src/lib/components/PropertyFilters/components/OperatorValueSelect.test.tsx@@ -0,0 +1,27 @@+import { PropertyOperator } from '~/types'++import { getValidationError } from './OperatorValueSelect'++describe('getValidationError', () => {+ it('validates every pattern of a multi-value regex filter without crashing on the array', () => {+ // A visited_page filter ORs several regex values, so the value is an array. RE2JS.compile+ // used to receive the array directly and throw "this.str.codePointAt is not a function",+ // surfacing that internal error to the user in the filter editor.+ const value = ['/project/[^/]+/replay/home', '/project/[^/]+/replay/playlists']++ expect(getValidationError(PropertyOperator.Regex, value)).toBeNull()+ })++ it('reports the first invalid pattern in a multi-value regex filter', () => {+ const value = ['/valid/path', '/bad(unclosed']++ const error = getValidationError(PropertyOperator.Regex, value)++ expect(error).not.toBeNull()+ expect(error).not.toContain('codePointAt')+ })++ it('still reports an invalid single-value regex', () => {+ expect(getValidationError(PropertyOperator.Regex, '(unclosed')).not.toBeNull()+ })+})diff --git a/frontend/src/lib/components/PropertyFilters/components/OperatorValueSelect.tsx b/frontend/src/lib/components/PropertyFilters/components/OperatorValueSelect.tsxindex 65cc65ddb05d..1ac44369165e 100644--- a/frontend/src/lib/components/PropertyFilters/components/OperatorValueSelect.tsx+++ b/frontend/src/lib/components/PropertyFilters/components/OperatorValueSelect.tsx@@ -157,17 +157,24 @@ interface OperatorSelectProps extends Omit<LemonSelectProps<any>, 'options'> {}function getRegexValidationError(operator: PropertyOperator, value: any): string | null {- if (isOperatorRegex(operator)) {+ if (!isOperatorRegex(operator)) {+ return null+ }+ // A regex operator can hold several values (e.g. a multi-value `visited_page` filter), so the+ // value is an array. RE2JS.compile expects a single string and crashes on an array, so validate+ // each pattern and surface the first that fails.+ const patterns: unknown[] = Array.isArray(value) ? value : [value]+ for (const pattern of patterns) {try {- RE2JS.compile(value)+ RE2JS.compile(String(pattern))} catch (error) {- return formatRE2Error(error as Error, value)+ return formatRE2Error(error as Error, String(pattern))}}return null}-function getValidationError(operator: PropertyOperator, value: any, property?: string): string | null {+export function getValidationError(operator: PropertyOperator, value: any, property?: string): string | null {const regexErrorMessage = getRegexValidationError(operator, value)if (regexErrorMessage != null) {return regexErrorMessage