Skip to content

Commit cc878b5

Browse files
committed
fix: add validation helpers to enforce regex validations for name fields
Signed-off-by: vikhy-aws <[email protected]>
1 parent 32c7c84 commit cc878b5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main/kotlin/org/opensearch/commons/utils/ValidationHelpers.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,24 @@ fun validateIamRoleArn(roleArn: String) {
7575
require(roleArnRegex.matcher(roleArn).find()) { "Invalid AWS role ARN: $roleArn " }
7676
}
7777

78-
fun isValidName(name: String): Boolean {
78+
fun isValidQueryName(name: String): Boolean {
7979
// Regex to restrict string so that it cannot start with [_, -, +],
8080
// contain two consecutive periods or contain invalid chars
8181
val regex = Regex("""^(?![_\-\+])(?!.*\.\.)[^$INVALID_NAME_CHARS]+$""")
8282

8383
return name.matches(regex)
8484
}
8585

86+
fun isValidName(name: String): Boolean {
87+
// Start with letter or underscore
88+
// Followed by letters, numbers, underscore or hyphen
89+
// Total length between 4 and 50 characters
90+
val regex = Regex("^[a-zA-Z_][a-zA-Z0-9_-]{3,49}$")
91+
return name.matches(regex)
92+
}
93+
94+
95+
8696
fun getInvalidNameChars(): String {
8797
return INVALID_NAME_CHARS
8898
}

0 commit comments

Comments
 (0)