Skip to content

Commit f46ff9e

Browse files
authored
Improve port bindings validation to follow Docker specification (#1019)
This PR updates the frontend validation for port bindings to fully support the Docker specification. Previously, the input validation only allowed the port:port format, which is incomplete Examples that are now accepted: - "3000" - "3000-3005" - "8000:8000" - "9090-9091:8080-8081" - "49100:22" - "8000-9000:80" - "127.0.0.1:8001:8001" - "127.0.0.1:5000-5010:5000-5010" - "::1:6000:6000" - "[::1]:6001:6001" - "6060:6060/udp" Signed-off-by: Jasmina <jasmina.piric@secomind.com>
1 parent 1f5a34b commit f46ff9e

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

frontend/src/forms/CreateRelease.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ const ContainerForm = ({
10181018
{...register(`containers.${index}.portBindings` as const)}
10191019
type="text"
10201020
isInvalid={!!errors.containers?.[index]?.portBindings}
1021-
placeholder="e.g., 8080:80, 443:443"
1021+
placeholder="e.g., 8080:80, 6060:6060/udp, 127.0.0.1:8001:8001"
10221022
/>
10231023
<Form.Control.Feedback type="invalid">
10241024
{errors.containers?.[index]?.portBindings?.message && (

frontend/src/forms/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const messages = defineMessages({
8585
portBindingsFormat: {
8686
id: "validation.portBindings.format",
8787
defaultMessage:
88-
"Port Bindings must be comma-separated values like '8080:80, 443:443'.",
88+
"Port Bindings must be comma-separated values in the format [HOST:]CONTAINER[/PROTOCOL]",
8989
},
9090
bindsInvalid: {
9191
id: "validation.binds.format",
@@ -234,6 +234,11 @@ const envSchema = yup
234234
})
235235
.default("{}");
236236

237+
const ipv4PortRegex =
238+
/^(\d{1,5}(-\d{1,5})?(:(\d{1,5}(-\d{1,5})?))?(\/(tcp|udp))?|(\d{1,3}\.){3}\d{1,3}:\d{1,5}(-\d{1,5})?:\d{1,5}(-\d{1,5})?(\/(tcp|udp))?)$/;
239+
const ipv6PortRegex =
240+
/^(\[?[0-9a-fA-F:]+\]?:\d{1,5}(-\d{1,5})?:\d{1,5}(-\d{1,5})?(\/(tcp|udp))?)$/;
241+
237242
const portBindingsSchema = yup
238243
.string()
239244
.nullable()
@@ -243,7 +248,11 @@ const portBindingsSchema = yup
243248
message: messages.portBindingsFormat.id,
244249
test: (value) =>
245250
!value ||
246-
value.split(", ").every((v) => /^[0-9]+:[0-9]+$/.test(v.trim())),
251+
value
252+
.split(", ")
253+
.every(
254+
(v) => ipv4PortRegex.test(v.trim()) || ipv6PortRegex.test(v.trim()),
255+
),
247256
});
248257

249258
const bindingsSchema = yup

frontend/src/i18n/langs/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2540,7 +2540,7 @@
25402540
"defaultMessage": "{label} must be a positive number."
25412541
},
25422542
"validation.portBindings.format": {
2543-
"defaultMessage": "Port Bindings must be comma-separated values like '8080:80, 443:443'."
2543+
"defaultMessage": "Port Bindings must be comma-separated values in the format [HOST:]CONTAINER[/PROTOCOL]"
25442544
},
25452545
"validation.required": {
25462546
"defaultMessage": "Required."

0 commit comments

Comments
 (0)