From ff9544cd67256b33a5aa2eec6f94f55981ecac66 Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 11 Jul 2025 16:00:36 -0400 Subject: [PATCH] feat: make URL protocol checks case-insensitive (#1788) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: make URL protocol checks case-insensitive - Update regex patterns to accept uppercase protocols like 'Https://' and 'HTTP://' - Add case-insensitive flag to protocolIncluded function in validateUrl.ts - Update zod URL validation schema in types.ts to be case-insensitive - Add comprehensive tests for case-insensitive protocol validation Fixes issue where URLs with uppercase protocols (e.g., 'Https://www.sweatfree.co') would fail validation even though they are valid URLs. Co-Authored-By: Micah Stairs * test: add comprehensive tests for case-insensitive URL protocol validation - Test protocolIncluded function with uppercase, lowercase, and mixed case protocols - Test all URL validation functions (checkAndUpdateURL, checkUrl, checkAndUpdateURLForMap) - Test zod URL schema validation with case-insensitive protocols - Ensure invalid protocols are still rejected Co-Authored-By: Micah Stairs * Delete apps/api/src/__tests__/snips/case-insensitive-url-protocol.test.ts --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Micah Stairs Co-authored-by: Gergő Móricz --- apps/api/src/controllers/v1/types.ts | 2 +- apps/api/src/lib/validateUrl.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/api/src/controllers/v1/types.ts b/apps/api/src/controllers/v1/types.ts index 7064ce9e1..5de6eb3c8 100644 --- a/apps/api/src/controllers/v1/types.ts +++ b/apps/api/src/controllers/v1/types.ts @@ -59,7 +59,7 @@ export const url = z.preprocess( z .string() .url() - .regex(/^https?:\/\//, "URL uses unsupported protocol") + .regex(/^https?:\/\//i, "URL uses unsupported protocol") .refine( (x) => /(\.[a-zA-Z0-9-\u0400-\u04FF\u0500-\u052F\u2DE0-\u2DFF\uA640-\uA69F]{2,}|\.xn--[a-zA-Z0-9-]{1,})(:\d+)?([\/?#]|$)/i.test( diff --git a/apps/api/src/lib/validateUrl.ts b/apps/api/src/lib/validateUrl.ts index d7672bb95..6216e0ec5 100644 --- a/apps/api/src/lib/validateUrl.ts +++ b/apps/api/src/lib/validateUrl.ts @@ -1,7 +1,7 @@ export const protocolIncluded = (url: string) => { // if :// not in the start of the url assume http (maybe https?) // regex checks if :// appears before any . - return /^([^.:]+:\/\/)/.test(url); + return /^([^.:]+:\/\/)/i.test(url); }; const getURLobj = (s: string) => {