Skip to content

Commit

Permalink
Add input validation for instance name in CreateOrEditHttpRouteModal.vue
Browse files Browse the repository at this point in the history
  • Loading branch information
stephdl committed Feb 7, 2024
1 parent 5fd35ba commit 3c2bd5b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions core/ui/src/components/settings/CreateOrEditHttpRouteModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,23 @@ export default {
this.clearErrors();
this.$emit("hide");
},
validateInput(prop) {
const allowedCharsRegex = /^[a-zA-Z0-9\-_]+$/;
let badChars = prop.match(/[^a-zA-Z0-9\-_]/g);
if (badChars && !allowedCharsRegex.test(prop)) {
// replace space with _(space) for better readability
badChars = badChars.map(char => char === ' ' ? '_(space)' : char);
return {
isValid: false,
badChars: badChars ? [...new Set(badChars)] : null
};
}

return {
isValid: true,
badChars: null
};
},
validateSetRoute(isEditingRoute) {
this.clearErrors();

Expand Down Expand Up @@ -307,6 +324,18 @@ export default {
}
}
}
// Instance name validation
const validationResult = this.validateInput(this.instance);
if (!validationResult.isValid) {
this.error.instance = this.$t("settings_http_routes.bad_characters", {
badChars: validationResult.badChars.join(", ")
});

if (isValidationOk) {
this.focusElement("instance");
isValidationOk = false;
}
}

// node

Expand Down

0 comments on commit 3c2bd5b

Please sign in to comment.