Compare commits
1 Commits
proof-chec
...
v1-policy-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3e2ac07fc |
@@ -5,6 +5,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -102,10 +103,10 @@ func tokenize(str string) []string {
|
|||||||
ctx := ""
|
ctx := ""
|
||||||
|
|
||||||
for col < len(str) {
|
for col < len(str) {
|
||||||
char := string(str[col])
|
char, size := utf8.DecodeRuneInString(str[col:])
|
||||||
|
|
||||||
if char == "\"" && string(str[col-1]) != "\\" {
|
if char == '"' && (col == 0 || str[col-1] != '\\') {
|
||||||
col++
|
col += size
|
||||||
if ctx == "\"" {
|
if ctx == "\"" {
|
||||||
ctx = ""
|
ctx = ""
|
||||||
} else {
|
} else {
|
||||||
@@ -115,17 +116,17 @@ func tokenize(str string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ctx == "\"" {
|
if ctx == "\"" {
|
||||||
col++
|
col += size
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if char == "." || char == "[" {
|
if char == '.' || char == '[' {
|
||||||
if ofs < col {
|
if ofs < col {
|
||||||
toks = append(toks, str[ofs:col])
|
toks = append(toks, str[ofs:col])
|
||||||
}
|
}
|
||||||
ofs = col
|
ofs = col
|
||||||
}
|
}
|
||||||
col++
|
col += size
|
||||||
}
|
}
|
||||||
|
|
||||||
if ofs < col && ctx != "\"" {
|
if ofs < col && ctx != "\"" {
|
||||||
|
|||||||
30
pkg/policy/selector/parsing_test.go
Normal file
30
pkg/policy/selector/parsing_test.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package selector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTokenizeUTF8(t *testing.T) {
|
||||||
|
t.Run("simple UTF-8", func(t *testing.T) {
|
||||||
|
str := ".こんにちは[0]"
|
||||||
|
expected := []string{".", "こんにちは", "[0]"}
|
||||||
|
actual := tokenize(str)
|
||||||
|
require.Equal(t, expected, actual)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("UTF-8 with quotes", func(t *testing.T) {
|
||||||
|
str := ".こんにちは[\"привет\"]"
|
||||||
|
expected := []string{".", "こんにちは", "[\"привет\"]"}
|
||||||
|
actual := tokenize(str)
|
||||||
|
require.Equal(t, expected, actual)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("UTF-8 with escaped quotes", func(t *testing.T) {
|
||||||
|
str := ".こんにちは[\"привет \\\"мир\\\"\"]"
|
||||||
|
expected := []string{".", "こんにちは", "[\"привет \\\"мир\\\"\"]"}
|
||||||
|
actual := tokenize(str)
|
||||||
|
require.Equal(t, expected, actual)
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user