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

View File

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