fieldRegex to be more restrictive and consistent

This commit is contained in:
Fabio Bozzo
2024-12-02 19:18:01 +01:00
parent e9105896d7
commit 3688ccea01
2 changed files with 11 additions and 11 deletions

View File

@@ -14,17 +14,16 @@ var (
indexRegex = regexp.MustCompile(`^-?\d+$`)
sliceRegex = regexp.MustCompile(`^((\-?\d+:\-?\d*)|(\-?\d*:\-?\d+))$`)
// - Unicode letters
// - Unicode combining marks
// - Unicode digits
// - Unicode connector punctuation
// - $, _
// - hyphen (-)
// \p{L} - any kind of letter from any language
// \p{Mn}\p{Mc} - combining marks and spacing combining marks
// \p{Nd} - decimal numbers
// \p{Pc} - connector punctuation (like underscore)
fieldRegex = regexp.MustCompile(`^\.[a-zA-Z_\p{L}][a-zA-Z$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}-]*?$`)
// Field name requirements:
// - Must start with ASCII letter, Unicode letter, or underscore
// - Can contain:
// - ASCII letters (a-z, A-Z)
// - ASCII digits (0-9)
// - Unicode letters (\p{L})
// - Dollar sign ($)
// - Underscore (_)
// - Hyphen (-)
fieldRegex = regexp.MustCompile(`^\.[a-zA-Z_\p{L}][a-zA-Z0-9$_\p{L}\-]*$`)
)
func Parse(str string) (Selector, error) {

View File

@@ -6,6 +6,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
"github.com/ucan-wg/go-ucan/pkg/policy/limits"
)