Skip to content

Commit

Permalink
feat: add support for buildpack urns (#3689)
Browse files Browse the repository at this point in the history
  • Loading branch information
jose-fully-ported authored Sep 29, 2023
1 parent 4c345eb commit 3dfa522
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import React, { useState } from "react";
import styled, { keyframes } from "styled-components";
import { Buildpack } from "../../types/buildpack";

function isValidURL(url: string): boolean {
function isValidBuildpack(url: string): boolean {
const urnPrefix = "urn:cnb:registry:";
if (url.startsWith(urnPrefix)) {
return true;
}

const pattern = /^(https?:\/\/)?([\w.-]+)\.([a-z]{2,})(:\d{2,5})?([\/\w.-]*)*\/?$/i;
return pattern.test(url);
}
Expand All @@ -15,7 +20,7 @@ const AddCustomBuildpackComponent: React.FC<{
const [error, setError] = useState(false);

const handleAddCustomBuildpack = () => {
if (buildpackUrl === "" || !isValidURL(buildpackUrl)) {
if (buildpackUrl === "" || !isValidBuildpack(buildpackUrl)) {
setError(true);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { Buildpack } from "main/home/app-dashboard/types/buildpack";
import React, { useState } from "react";
import styled, { keyframes } from "styled-components";

function isValidURL(url: string): boolean {
function isValidBuildpack(url: string): boolean {
const urnPrefix = "urn:cnb:registry:";
if (url.startsWith(urnPrefix)) {
return true;
}

const pattern = /^(https?:\/\/)?([\w.-]+)\.([a-z]{2,})(:\d{2,5})?([\/\w.-]*)*\/?$/i;
return pattern.test(url);
}
Expand All @@ -15,7 +20,7 @@ const AddCustomBuildpack: React.FC<{
const [error, setError] = useState(false);

const handleAddCustomBuildpack = () => {
if (buildpackUrl === "" || !isValidURL(buildpackUrl)) {
if (buildpackUrl === "" || !isValidBuildpack(buildpackUrl)) {
setError(true);
return;
}
Expand Down

0 comments on commit 3dfa522

Please sign in to comment.