Skip to content

Commit b110ced

Browse files
committed
fix: consolidate CUID validation into single shared regex
Reuse cuidRegex from browsers.go in looksLikeCUID and update the regex to require the first character to be a letter (matching the cuid2 spec). Made-with: Cursor
1 parent 73aca64 commit b110ced

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

cmd/browsers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ type Int64Flag struct {
118118
Value int64
119119
}
120120

121-
// Regular expression to validate CUID2 identifiers (24 lowercase alphanumeric characters).
122-
var cuidRegex = regexp.MustCompile(`^[a-z0-9]{24}$`)
121+
// Regular expression to validate CUID2 identifiers (starts with a letter, 24 lowercase alphanumeric characters).
122+
var cuidRegex = regexp.MustCompile(`^[a-z][a-z0-9]{23}$`)
123123

124124
// getAvailableViewports returns the list of supported viewport configurations.
125125
func getAvailableViewports() []string {

cmd/root.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -254,22 +254,10 @@ func isUsageError(err error) bool {
254254
return false
255255
}
256256

257-
// looksLikeCUID returns true if s matches the cuid2 format used for resource IDs
258-
// (24 lowercase alphanumeric characters).
257+
// looksLikeCUID returns true if s matches the cuid2 format used for resource IDs.
258+
// Delegates to the shared cuidRegex defined in browsers.go.
259259
func looksLikeCUID(s string) bool {
260-
if len(s) != 24 {
261-
return false
262-
}
263-
for i, c := range s {
264-
if i == 0 {
265-
if !(c >= 'a' && c <= 'z') {
266-
return false
267-
}
268-
} else if !((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) {
269-
return false
270-
}
271-
}
272-
return true
260+
return cuidRegex.MatchString(s)
273261
}
274262

275263
// resolveProjectByName lists the caller's projects and returns the ID of the

0 commit comments

Comments
 (0)