Skip to content

: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.

fix(property-filters): trim whitespace from pasted filter values (#61255)

posthog[bot]78e1717184c3
diff --git a/frontend/src/lib/components/PropertyFilters/components/PropertyValue.test.tsx b/frontend/src/lib/components/PropertyFilters/components/PropertyValue.test.tsx
index e71ce8e775a1..864f589b22bb 100644
--- a/frontend/src/lib/components/PropertyFilters/components/PropertyValue.test.tsx
+++ b/frontend/src/lib/components/PropertyFilters/components/PropertyValue.test.tsx
@@ -152,6 +152,46 @@ describe('PropertyValue', () => {
expect(input).toHaveValue('user.*7$')
})
+ it.each([
+ {
+ label: 'trims surrounding whitespace from a pasted value before committing it',
+ propertyKey: '$ai_trace_id',
+ operator: PropertyOperator.Exact,
+ pastedValue: ' 9c8a6265-382a-4972-9640-b400dabdd83e ',
+ expectedArg: ['9c8a6265-382a-4972-9640-b400dabdd83e'],
+ },
+ {
+ label: 'preserves surrounding whitespace for regex operators, where it can be meaningful',
+ propertyKey: '$current_url',
+ operator: PropertyOperator.Regex,
+ pastedValue: 'foo ',
+ expectedArg: 'foo ',
+ },
+ ])('$label', async ({ propertyKey, operator, pastedValue, expectedArg }) => {
+ const onSet = jest.fn()
+ render(
+ <Provider>
+ <PropertyValue
+ propertyKey={propertyKey}
+ type={PropertyFilterType.Event}
+ operator={operator}
+ onSet={onSet}
+ value={[]}
+ />
+ </Provider>
+ )
+
+ const user = userEvent.setup()
+ const input = screen.getByRole('textbox')
+ await user.click(input)
+ await user.paste(pastedValue)
+ await user.keyboard('{Enter}')
+
+ await waitFor(() => {
+ expect(onSet).toHaveBeenCalledWith(expectedArg)
+ })
+ })
+
it('keeps numeric-only input for non-regex numeric properties', async () => {
propertyDefinitionsModel.actions.updatePropertyDefinitions({
'event/userId': {
diff --git a/frontend/src/lib/components/PropertyFilters/components/PropertyValue.tsx b/frontend/src/lib/components/PropertyFilters/components/PropertyValue.tsx
index 15dba1115427..46e30543c47d 100644
--- a/frontend/src/lib/components/PropertyFilters/components/PropertyValue.tsx
+++ b/frontend/src/lib/components/PropertyFilters/components/PropertyValue.tsx
@@ -444,7 +444,14 @@ export function PropertyValue({
: undefined
}
onChange={(nextVal) => {
- const newValues = nextVal.filter((v) => !formattedValues.includes(String(v)))
+ // Trim whitespace so a stray leading/trailing space (common when pasting an ID)
+ // doesn't silently break the filter — the snack display hides the space.
+ // Skip regex operators, where leading/trailing whitespace can be a meaningful
+ // part of the pattern (e.g. `^ foo`, `bar $`).
+ const trimmedVal = isOperatorRegex(operator)
+ ? nextVal
+ : nextVal.map((v) => (typeof v === 'string' ? v.trim() : v))
+ const newValues = trimmedVal.filter((v) => !formattedValues.includes(String(v)))
if (newValues.length > 0) {
const availableValues = new Set(displayOptions.map((o) => toString(o.name)))
const fromSuggestion = newValues.every((v) => availableValues.has(toString(v)))
@@ -457,7 +464,7 @@ export function PropertyValue({
had_search_input: currentSearchInput.current !== '',
})
}
- isMultiSelect ? setValue(nextVal) : setValue(nextVal[0])
+ isMultiSelect ? setValue(trimmedVal) : setValue(trimmedVal[0])
}}
onInputChange={onSearchTextChange}
placeholder={placeholder}