aboutsummaryrefslogtreecommitdiffstats
path: root/frontends
diff options
context:
space:
mode:
authorMiodrag Milanović <mmicko@gmail.com>2022-03-04 13:57:32 +0100
committerGitHub <noreply@github.com>2022-03-04 13:57:32 +0100
commitc3124023e441c99dbdff40cb730d5b05499a378d (patch)
tree4c1aea11c042553307d7c5895be6f4df480ed13c /frontends
parent7be7f5e02eaa0ed0ade5d6119fb2f2340586b67d (diff)
parent8fd1b062491f9ba1f0aed570086e7697731502d4 (diff)
downloadyosys-c3124023e441c99dbdff40cb730d5b05499a378d.tar.gz
yosys-c3124023e441c99dbdff40cb730d5b05499a378d.tar.bz2
yosys-c3124023e441c99dbdff40cb730d5b05499a378d.zip
Merge pull request #3207 from nakengelhardt/json_escape_quotes
fix handling of escaped chars in json backend and frontend (mostly)
Diffstat (limited to 'frontends')
-rw-r--r--frontends/json/jsonparse.cc34
1 files changed, 31 insertions, 3 deletions
diff --git a/frontends/json/jsonparse.cc b/frontends/json/jsonparse.cc
index 50c25abda..1aab81015 100644
--- a/frontends/json/jsonparse.cc
+++ b/frontends/json/jsonparse.cc
@@ -60,10 +60,38 @@ struct JsonNode
break;
if (ch == '\\') {
- int ch = f.get();
+ ch = f.get();
- if (ch == EOF)
- log_error("Unexpected EOF in JSON string.\n");
+ switch (ch) {
+ case EOF: log_error("Unexpected EOF in JSON string.\n"); break;
+ case '"':
+ case '/':
+ case '\\': break;
+ case 'b': ch = '\b'; break;
+ case 'f': ch = '\f'; break;
+ case 'n': ch = '\n'; break;
+ case 'r': ch = '\r'; break;
+ case 't': ch = '\t'; break;
+ case 'u':
+ int val = 0;
+ for (int i = 0; i < 4; i++) {
+ ch = f.get();
+ val <<= 4;
+ if (ch >= '0' && '9' >= ch) {
+ val += ch - '0';
+ } else if (ch >= 'A' && 'F' >= ch) {
+ val += 10 + ch - 'A';
+ } else if (ch >= 'a' && 'f' >= ch) {
+ val += 10 + ch - 'a';
+ } else
+ log_error("Unexpected non-digit character in \\uXXXX sequence: %c.\n", ch);
+ }
+ if (val < 128)
+ ch = val;
+ else
+ log_error("Unsupported \\uXXXX sequence in JSON string: %04X.\n", val);
+ break;
+ }
}
data_string += ch;