mirror of
https://github.com/google/go-jsonnet.git
synced 2025-09-28 17:01:02 +02:00
fix: use rune for length over string
This commit is contained in:
parent
03df4dc6e9
commit
3aab052ecc
@ -1179,7 +1179,7 @@ func builtinSubstr(i *interpreter, inputStr, inputFrom, inputLen value) (value,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fromInt := int(fromV.value)
|
fromInt := int(fromV.value)
|
||||||
strStr := strV.getGoString()
|
strStr := strV.getRunes()
|
||||||
|
|
||||||
endIndex := fromInt + lenInt
|
endIndex := fromInt + lenInt
|
||||||
|
|
||||||
@ -1190,9 +1190,7 @@ func builtinSubstr(i *interpreter, inputStr, inputFrom, inputLen value) (value,
|
|||||||
if fromInt > len(strStr) {
|
if fromInt > len(strStr) {
|
||||||
return makeValueString(""), nil
|
return makeValueString(""), nil
|
||||||
}
|
}
|
||||||
|
return makeValueString(string(strStr[fromInt:endIndex])), nil
|
||||||
runes := []rune(strStr)
|
|
||||||
return makeValueString(string(runes[fromInt:endIndex])), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func builtinSplitLimit(i *interpreter, strv, cv, maxSplitsV value) (value, error) {
|
func builtinSplitLimit(i *interpreter, strv, cv, maxSplitsV value) (value, error) {
|
||||||
|
1
testdata/builtin_substr_multibyte.golden
vendored
Normal file
1
testdata/builtin_substr_multibyte.golden
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
"🤩"
|
1
testdata/builtin_substr_multibyte.jsonnet
vendored
Normal file
1
testdata/builtin_substr_multibyte.jsonnet
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
std.substr("🤩", 0, 5)
|
0
testdata/builtin_substr_multibyte.linter.golden
vendored
Normal file
0
testdata/builtin_substr_multibyte.linter.golden
vendored
Normal file
Loading…
x
Reference in New Issue
Block a user