From 07c65abc6fb6300ea48a89e0cc5e7ff2dafbd8d3 Mon Sep 17 00:00:00 2001 From: Feroze Mohideen Date: Tue, 3 Oct 2023 10:57:59 -0400 Subject: [PATCH] fix parsing of custom buildpack urls (#3713) --- .../buildpacks/AddCustomBuildpackComponent.tsx | 9 ++++++--- .../build-settings/buildpacks/AddCustomBuildpack.tsx | 11 +++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/dashboard/src/main/home/app-dashboard/build-settings/buildpacks/AddCustomBuildpackComponent.tsx b/dashboard/src/main/home/app-dashboard/build-settings/buildpacks/AddCustomBuildpackComponent.tsx index 39fc99b2a4..7389cf8b89 100644 --- a/dashboard/src/main/home/app-dashboard/build-settings/buildpacks/AddCustomBuildpackComponent.tsx +++ b/dashboard/src/main/home/app-dashboard/build-settings/buildpacks/AddCustomBuildpackComponent.tsx @@ -8,9 +8,12 @@ function isValidBuildpack(url: string): boolean { if (url.startsWith(urnPrefix)) { return true; } - - const pattern = /^(https?:\/\/)?([\w.-]+)\.([a-z]{2,})(:\d{2,5})?([\/\w.-]*)*\/?$/i; - return pattern.test(url); + try { + new URL(url); + return true; + } catch (error) { + return false; + } } const AddCustomBuildpackComponent: React.FC<{ diff --git a/dashboard/src/main/home/app-dashboard/validate-apply/build-settings/buildpacks/AddCustomBuildpack.tsx b/dashboard/src/main/home/app-dashboard/validate-apply/build-settings/buildpacks/AddCustomBuildpack.tsx index 0dc5759163..a1afdaec13 100644 --- a/dashboard/src/main/home/app-dashboard/validate-apply/build-settings/buildpacks/AddCustomBuildpack.tsx +++ b/dashboard/src/main/home/app-dashboard/validate-apply/build-settings/buildpacks/AddCustomBuildpack.tsx @@ -8,9 +8,12 @@ function isValidBuildpack(url: string): boolean { if (url.startsWith(urnPrefix)) { return true; } - - const pattern = /^(https?:\/\/)?([\w.-]+)\.([a-z]{2,})(:\d{2,5})?([\/\w.-]*)*\/?$/i; - return pattern.test(url); + try { + new URL(url); + return true; + } catch (error) { + return false; + } } const AddCustomBuildpack: React.FC<{ @@ -53,7 +56,7 @@ const AddCustomBuildpack: React.FC<{ - handleAddCustomBuildpack()}> + handleAddCustomBuildpack()} type="button"> add