From 17cc70f36ed48cc2cb9e69c43d40eb79efdcd6b4 Mon Sep 17 00:00:00 2001 From: "Siddharth Gelera (reaper)" Date: Wed, 5 Nov 2025 20:11:00 +0530 Subject: [PATCH] fix: improve URL validation in GenerateCodeItem (#5998) * fix: improve URL validation in GenerateCodeItem Replaced direct URL validation with a new function to check for valid URLs and missing interpolations. * Update packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../CollectionItem/GenerateCodeItem/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js index f7fc6111c..728cb7a7b 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/index.js @@ -14,6 +14,14 @@ import { useSelector } from 'react-redux'; import { getAllVariables, getGlobalEnvironmentVariables } from 'utils/collections/index'; import { resolveInheritedAuth } from './utils/auth-utils'; +const TEMPLATE_VAR_PATTERN = /\{\{([^}]+)\}\}/g; + +const validateURLWithVars = (url) => { + const isValid = isValidUrl(url); + const hasMissingInterpolations = TEMPLATE_VAR_PATTERN.test(url); + return isValid && !hasMissingInterpolations; +}; + const GenerateCodeItem = ({ collectionUid, item, onClose, isExample = false, exampleUid = null }) => { const languages = getLanguages(); const collection = useSelector(state => state.collections.collections?.find(c => c.uid === collectionUid)); @@ -122,7 +130,7 @@ const GenerateCodeItem = ({ collectionUid, item, onClose, isExample = false, exa
- {isValidUrl(finalUrl) ? ( + {validateURLWithVars(finalUrl) ? (