aboutsummaryrefslogtreecommitdiffstats
path: root/backends
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 /backends
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 'backends')
-rw-r--r--backends/json/json.cc17
1 files changed, 16 insertions, 1 deletions
diff --git a/backends/json/json.cc b/backends/json/json.cc
index 4aa8046d6..42eedc606 100644
--- a/backends/json/json.cc
+++ b/backends/json/json.cc
@@ -52,8 +52,23 @@ struct JsonWriter
string newstr = "\"";
for (char c : str) {
if (c == '\\')
+ newstr += "\\\\";
+ else if (c == '"')
+ newstr += "\\\"";
+ else if (c == '\b')
+ newstr += "\\b";
+ else if (c == '\f')
+ newstr += "\\f";
+ else if (c == '\n')
+ newstr += "\\n";
+ else if (c == '\r')
+ newstr += "\\r";
+ else if (c == '\t')
+ newstr += "\\t";
+ else if (c < 0x20)
+ newstr += stringf("\\u%04X", c);
+ else
newstr += c;
- newstr += c;
}
return newstr + "\"";
}