summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-05-23 14:22:30 -0400
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-05-23 14:22:30 -0400
commit53c98805e05b3e9fa4a6b9fd48d0dac977716f2c (patch)
tree7025ef1866425f965276c710a0779eca3540bcb5
parent04ddaf830a6dd6cd37ee21c06dcc6b326e93a1ef (diff)
disallow control characers in stringsmain
-rw-r--r--json.sh8
1 files changed, 5 insertions, 3 deletions
diff --git a/json.sh b/json.sh
index 535f20f..42e2f35 100644
--- a/json.sh
+++ b/json.sh
@@ -28,8 +28,9 @@
#
# Assumptions:
# - `set -e`
-# - Input is valid UTF-8
+# - Input is valid UTF-8, and does not include U+0000
# - LC_* is set to a UTF-8 value
+# - LC_COLLATE is set to C.UTF-8
json_tokenize() {
local _json_token=$1
@@ -138,7 +139,7 @@ _json_array() {
_json_string() {
_json_expect '"'
local _json_strval=''
- local _json_re='^[^\"]+'
+ local _json_re=$'^[^\x01-\x1f"\\]+'
local _json_c _json_n _json_n2
while true; do
case "${_json_buf::1}" in
@@ -186,13 +187,14 @@ _json_string() {
'' )
_json_error 'unexpected EOF in string'
;;
- * )
+ [\ -\[\]-$'\U0010FFFF'] )
# Consume multiple characters at once,
# or else this is horribly slow.
[[ $_json_buf =~ $_json_re ]]
_json_strval+=${BASH_REMATCH[0]}
_json_buf=${_json_buf#"${BASH_REMATCH[0]}"}
;;
+ *) _json_error 'illegal character in string: %q' "${json_buf::1}";;
esac
done
}