Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Route Builder rules should be case insensitive #9040

32 changes: 32 additions & 0 deletions packages/app-store/routing-forms/lib/jsonLogicOverrides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import jsonLogic from "json-logic-js";

// converts input to lowercase if string
function normalize(input: any) {
return typeof input === "string" ? input.toLowerCase() : input;
}

jsonLogic.add_operation("==", function (a: any, b: any) {
return normalize(a) == normalize(b);
});

jsonLogic.add_operation("===", function (a: any, b: any) {
return normalize(a) === normalize(b);
});

jsonLogic.add_operation("!==", function (a: any, b: any) {
return normalize(a) !== normalize(b);
});

jsonLogic.add_operation("!=", function (a: any, b: any) {
return normalize(a) != normalize(b);
});

jsonLogic.add_operation("in", function (a: any, b: any) {
const first = normalize(a);
const second = normalize(b);
if (!second || typeof second.indexOf === "undefined") return false;
hariombalhara marked this conversation as resolved.
Show resolved Hide resolved
return second.indexOf(first) !== -1;
});

export default jsonLogic;
2 changes: 1 addition & 1 deletion packages/app-store/routing-forms/lib/processRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { App_RoutingForms_Form } from "@prisma/client";
import jsonLogic from "json-logic-js";
import { Utils as QbUtils } from "react-awesome-query-builder";
import type { z } from "zod";

Expand All @@ -8,6 +7,7 @@ import type { zodNonRouterRoute } from "../zod";
import { getQueryBuilderConfig } from "./getQueryBuilderConfig";
import { isFallbackRoute } from "./isFallbackRoute";
import isRouter from "./isRouter";
import jsonLogic from "./jsonLogicOverrides";

export function processRoute({
form,
Expand Down