aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/helpers/projects.ts
diff options
context:
space:
mode:
authorPhilippe Perrin <philippe.perrin@sonarsource.com>2021-06-30 16:18:25 +0200
committersonartech <sonartech@sonarsource.com>2021-07-01 20:03:19 +0000
commitc1f985398916637be241e6f052bf5977e5fb28e3 (patch)
tree71030dbd3939c67303f25122d26f1905f3950c43 /server/sonar-web/src/main/js/helpers/projects.ts
parentb1aa89455e5650fbddf875a25b9cb5c6e65f9b98 (diff)
downloadsonarqube-c1f985398916637be241e6f052bf5977e5fb28e3.tar.gz
sonarqube-c1f985398916637be241e6f052bf5977e5fb28e3.zip
SONAR-14941 Improve the project manual creation form
Diffstat (limited to 'server/sonar-web/src/main/js/helpers/projects.ts')
-rw-r--r--server/sonar-web/src/main/js/helpers/projects.ts19
1 files changed, 10 insertions, 9 deletions
diff --git a/server/sonar-web/src/main/js/helpers/projects.ts b/server/sonar-web/src/main/js/helpers/projects.ts
index f326cce111f..7351d690f02 100644
--- a/server/sonar-web/src/main/js/helpers/projects.ts
+++ b/server/sonar-web/src/main/js/helpers/projects.ts
@@ -20,20 +20,21 @@
import { ProjectKeyValidationResult } from '../types/component';
import { PROJECT_KEY_MAX_LEN } from './constants';
+// This is the regex used on the backend:
+// [\p{Alnum}\-_.:]*[\p{Alpha}\-_.:]+[\p{Alnum}\-_.:]*
+// See sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java
+export const PROJECT_KEY_REGEX = /^[\w\-.:]*[a-z\-_.:]+[\w\-.:]*$/i;
+export const PROJECT_KEY_INVALID_CHARACTERS = /[^\w\-:.]+/gi;
+
export function validateProjectKey(projectKey: string): ProjectKeyValidationResult {
- // This is the regex used on the backend:
- // [\p{Alnum}\-_.:]*[\p{Alpha}\-_.:]+[\p{Alnum}\-_.:]*
- // See sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java
- const regex = /^[\w\-.:]*[a-z\-_.:]+[\w\-.:]*$/i;
if (projectKey.length === 0) {
return ProjectKeyValidationResult.Empty;
} else if (projectKey.length > PROJECT_KEY_MAX_LEN) {
return ProjectKeyValidationResult.TooLong;
- } else if (regex.test(projectKey)) {
+ } else if (PROJECT_KEY_REGEX.test(projectKey)) {
return ProjectKeyValidationResult.Valid;
- } else {
- return /^[0-9]+$/.test(projectKey)
- ? ProjectKeyValidationResult.OnlyDigits
- : ProjectKeyValidationResult.InvalidChar;
+ } else if (/^[0-9]+$/.test(projectKey)) {
+ return ProjectKeyValidationResult.OnlyDigits;
}
+ return ProjectKeyValidationResult.InvalidChar;
}