Skip to content

Commit 442a720

Browse files
committed
[#3495] Fix tools/check-for-json-errors-in-doc.sh
Fix tools/check-for-json-errors-in-doc.sh from escaping double-escaped characters in JSON which results in malformed JSON which results in CI failing.
1 parent 17fe5c2 commit 442a720

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

tools/check-for-json-errors-in-doc.sh

+10-8
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ for file in ${files}; do
4141
echo "processing: $file"
4242
IFS=
4343
content=$(tr '\n' '\r' < "${file}" | sed -r 's/,[[:blank:]]*\r[[:blank:]]*\.\.\.//g' | sed -r 's/\\[[:blank:]]*\r[[:blank:]]*//g' | tr '\r' '\n')
44-
stop_at=$(echo "${content}" | wc -l)
44+
content="${content}
45+
"
46+
stop_at=$(printf '%s' "${content}" | wc -l)
4547
while true; do
4648
line_num=$((line_num + 1))
4749
if test "${line_num}" -gt "${stop_at}"; then
4850
break
4951
fi
50-
line=$(echo "${content}" | head -n "${line_num}" | tail -n 1)
52+
line=$(printf '%s' "${content}" | head -n "${line_num}" | tail -n 1)
5153
if [ $comment -eq 0 ] && [ $json -eq 0 ] && [ "$(echo "$line" | grep -c "^[A-Za-z]+\|^\s*\`")" -eq 1 ]; then
5254
# ignore line if it starts with 'A-Za-z' or spaces followed by '`'
5355
continue
@@ -65,7 +67,7 @@ for file in ${files}; do
6567
# if this is not a comment and the line starts with spaces followed by '{' or by '"' followed by "{"
6668
json=1
6769
# ignore any map name before top level map
68-
line=$(echo "$line" | sed 's/.*{/{/g')
70+
line=$(printf '%s' "${line}" | sed 's/.*{/{/g')
6971
echo > "${work_file}"
7072
elif [ $comment -eq 0 ] && [ $json -eq 1 ] && [ "$(echo "$line" | grep -c "^\s*[A-Za-z]\|^\s*\`")" -eq 1 ]; then
7173
# if the line is not a comment and the line starts with spaces followed by 'A-Za-z' or followed by "`" and the parser is processing a json structure
@@ -83,7 +85,8 @@ for file in ${files}; do
8385
if [ "$(echo "$line" | grep -c "^\s*\.\.\s")" -eq 1 ]; then
8486
echo >> "${work_file}"
8587
else
86-
# if file is .json the following replace in line are done:
88+
if [ "$(echo "$file" | grep -c "\.json")" -eq 0 ]; then
89+
# if file is .rst the following replace in line are done:
8790
# 1. delete everything after '#'
8891
# 2. delete everything after //
8992
# 3. ignore <?include?>
@@ -94,14 +97,13 @@ for file in ${files}; do
9497
# 8. replace ', ... ' with ' '
9598
# 9. replace ' <DATA>' with ' "placeholder": "value"'
9699
# 10. replace ' <DATA>' with ' "placeholder"'
97-
if [ "$(echo "$file" | grep -c "\.json")" -eq 0 ]; then
98-
echo "$line" | cut -d "#" -f 1 | sed 's/\/\/ .*//g' | sed 's/<?.*?>//g' | sed 's/\[ <\([-A-Za-z0-9 ]*\)> \]/\[ \"<\1>\" \]/g' | sed 's/ <\(.*\)>:/ \"<\1>\":/g' | sed 's/: <\(.*\)>/: \"<\1>\"/g' | sed 's/ \.\.\./ \"placeholder\": \"value\"/g' | sed 's/, \.\.\. / /g' | sed 's/ <\(.*\)>/ \"placeholder\": \"value\"/g' | sed 's/ <\(.*\)>/ \"placeholder\"/g' >> "${work_file}"
100+
printf '%s' "${line}" | cut -d "#" -f 1 | sed 's/\/\/ .*//g' | sed 's/<?.*?>//g' | sed 's/\[ <\([-A-Za-z0-9 ]*\)> \]/\[ \"<\1>\" \]/g' | sed 's/ <\(.*\)>:/ \"<\1>\":/g' | sed 's/: <\(.*\)>/: \"<\1>\"/g' | sed 's/ \.\.\./ \"placeholder\": \"value\"/g' | sed 's/, \.\.\. / /g' | sed 's/ <\(.*\)>/ \"placeholder\": \"value\"/g' | sed 's/ <\(.*\)>/ \"placeholder\"/g' >> "${work_file}"
99101
else
100-
# if file is .rst the following replace in line are done:
102+
# if file is .json the following replace in line are done:
101103
# 1. delete everything after '#'
102104
# 2. delete everything after //
103105
# 3. ignore <?include?>
104-
echo "$line" | cut -d "#" -f 1 | sed 's/\/\/ .*//g' | sed 's/<?.*?>//g' >> "${work_file}"
106+
printf '%s' "${line}" | cut -d "#" -f 1 | sed 's/\/\/ .*//g' | sed 's/<?.*?>//g' >> "${work_file}"
105107
fi
106108
fi
107109
fi

0 commit comments

Comments
 (0)