Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(filters): escape pipe character in filter URL encoding (#11758)

tejasf307faa53a55
diff --git a/web/src/features/filters/filter-integration.clienttest.ts b/web/src/features/filters/filter-integration.clienttest.ts
index 0601617166..1bad454c82 100644
--- a/web/src/features/filters/filter-integration.clienttest.ts
+++ b/web/src/features/filters/filter-integration.clienttest.ts
@@ -188,7 +188,7 @@ describe("Filter Query Encoding Integration (Full URL Lifecycle)", () => {
],
},
{
- description: "pipe characters in array values",
+ description: "pipe as delimiter between array values",
filters: [
{
column: "period",
@@ -198,6 +198,28 @@ describe("Filter Query Encoding Integration (Full URL Lifecycle)", () => {
},
],
},
+ {
+ description: "literal pipe characters within values (issue #11757)",
+ filters: [
+ {
+ column: "name",
+ type: "stringOptions",
+ operator: "any of",
+ value: ["Builder | Short Research"],
+ },
+ ],
+ },
+ {
+ description: "multiple values with literal pipes",
+ filters: [
+ {
+ column: "name",
+ type: "stringOptions",
+ operator: "any of",
+ value: ["Builder | Short Research", "Another | Value"],
+ },
+ ],
+ },
{
description: "operators with URL-unsafe chars (>=, <=)",
filters: [
diff --git a/web/src/features/filters/hooks/useFilterState.ts b/web/src/features/filters/hooks/useFilterState.ts
index fe1226df47..c04f261c59 100644
--- a/web/src/features/filters/hooks/useFilterState.ts
+++ b/web/src/features/filters/hooks/useFilterState.ts
@@ -21,6 +21,11 @@ import {
import useSessionStorage from "@/src/components/useSessionStorage";
import { evalConfigFilterColumns } from "@/src/server/api/definitions/evalConfigsTable";
import { evalExecutionsFilterCols } from "@/src/server/api/definitions/evalExecutionsTable";
+import {
+ escapePipeInValue,
+ splitOnUnescapedPipe,
+ unescapePipeInValue,
+} from "../lib/filter-query-encoding";
const DEBUG_QUERY_STATE = false;
@@ -50,7 +55,7 @@ const getCommaArrayParam = (table: TableName) => ({
: f.type === "stringOptions" ||
f.type === "arrayOptions" ||
f.type === "categoryOptions"
- ? f.value.join("|")
+ ? (f.value as string[]).map(escapePipeInValue).join("|")
: f.value,
)}`;
@@ -80,7 +85,7 @@ const getCommaArrayParam = (table: TableName) => ({
: type === "stringOptions" ||
type === "arrayOptions" ||
type === "categoryOptions"
- ? decodedValue.split("|")
+ ? splitOnUnescapedPipe(decodedValue).map(unescapePipeInValue)
: type === "boolean"
? decodedValue === "true"
: decodedValue;
diff --git a/web/src/features/filters/lib/filter-query-encoding-decoding.clienttest.ts b/web/src/features/filters/lib/filter-query-encoding-decoding.clienttest.ts
index ea7edc5b81..b54e1503bf 100644
--- a/web/src/features/filters/lib/filter-query-encoding-decoding.clienttest.ts
+++ b/web/src/features/filters/lib/filter-query-encoding-decoding.clienttest.ts
@@ -456,6 +456,47 @@ describe("Filter Query Encoding & Decoding (Legacy Format)", () => {
expect(deserialized).toEqual(filterWithEmptyString);
});
+ it("should maintain consistency for values containing pipes", () => {
+ // Issue #11757: values with literal | should round-trip correctly
+ const cases: FilterState[] = [
+ [
+ {
+ column: "name",
+ type: "stringOptions",
+ operator: "any of",
+ value: ["Builder | Short Research"],
+ },
+ ],
+ [
+ {
+ column: "name",
+ type: "stringOptions",
+ operator: "any of",
+ value: [
+ "Builder | Short Research",
+ "Regular Value",
+ "Another | Pipe | Value",
+ ],
+ },
+ ],
+ [
+ {
+ column: "name",
+ type: "stringOptions",
+ operator: "any of",
+ value: ["path\\to\\file | description", "normal | value"],
+ },
+ ],
+ ];
+
+ for (const filters of cases) {
+ const serialized = encodeFilters(filters);
+ const deserialized = decodeFilters(serialized);
+
+ expect(deserialized).toEqual(filters);
+ }
+ });
+
it("should maintain consistency for mixed filter types", () => {
const mixedFilters: FilterState = [
{
diff --git a/web/src/features/filters/lib/filter-query-encoding.ts b/web/src/features/filters/lib/filter-query-encoding.ts
index 5433d59255..b4ec184b1d 100644
--- a/web/src/features/filters/lib/filter-query-encoding.ts
+++ b/web/src/features/filters/lib/filter-query-encoding.ts
@@ -5,6 +5,42 @@ import {
} from "@langfuse/shared";
import { encodeDelimitedArray, decodeDelimitedArray } from "use-query-params";
+// Escape pipe characters in values to avoid conflicts with the delimiter
+// Uses backslash escaping: | → \|, and \ → \\
+export function escapePipeInValue(value: string): string {
+ return value.replace(/\\/g, "\\\\").replace(/\|/g, "\\|");
+}
+
+export function unescapePipeInValue(value: string): string {
+ return value.replace(/\\\|/g, "|").replace(/\\\\/g, "\\");
+}
+
+// Split on unescaped pipe characters only (pipes not preceded by backslash)
+export function splitOnUnescapedPipe(str: string): string[] {
+ const result: string[] = [];
+ let current = "";
+ let i = 0;
+
+ while (i < str.length) {
+ if (str[i] === "\\" && i + 1 < str.length) {
+ // Escaped character - include both backslash and next char
+ current += str[i] + str[i + 1];
+ i += 2;
+ } else if (str[i] === "|") {
+ // Unescaped pipe - split here
+ result.push(current);
+ current = "";
+ i++;
+ } else {
+ current += str[i];
+ i++;
+ }
+ }
+ result.push(current);
+
+ return result;
+}
+
// Generic helpers for reusable encoding/decoding across feature areas
export type GenericFilterOptions = Record<
string,
@@ -53,7 +89,9 @@ export function encodeFiltersGeneric(filters: FilterState): string {
f.type === "arrayOptions" ||
f.type === "categoryOptions"
) {
- encodedValue = encodeURIComponent((f.value as string[]).join("|"));
+ // Escape pipe characters in individual values before joining with pipe delimiter
+ const escapedValues = (f.value as string[]).map(escapePipeInValue);
+ encodedValue = encodeURIComponent(escapedValues.join("|"));
} else {
encodedValue = encodeURIComponent(String(f.value));
}
@@ -102,8 +140,9 @@ export function decodeFiltersGeneric(query: string): FilterState {
type === "arrayOptions" ||
type === "categoryOptions"
) {
+ // Split on unescaped pipe characters only, then unescape each value
parsedValue = decodedValue
- ? decodedValue.split("|")
+ ? splitOnUnescapedPipe(decodedValue).map(unescapePipeInValue)
: decodedValue === ""
? [""] // allow empty strings (i.e, filter for empty trace name)
: [decodedValue];