Hey Northwoods,
we’re running into an issue where Model.toJson
doesn’t escape the double quote character ("
) in javascript object keys, when used in normal go.ObjectData’s.
Here’s an example that produces the bug for me in latest chrome:
<html>
<body>
<div id="diagram" style="width: 100%; height: 90%"></div>
<script src="https://gojs.net/latest/release/go.js"></script>
<script>
const $ = go.GraphObject.make;
const diagram = $(go.Diagram, {
div: document.getElementById("diagram"),
model: $(go.GraphLinksModel, {
modelData: {
keyValues: {},
},
}),
});
const obj = { '"': '"' };
diagram.model.setDataProperty(diagram.model.modelData, "keyValues", obj);
const json = diagram.model.toJson();
console.log(json);
try {
// will throw
JSON.parse(json);
} catch (e) {
console.warn(e);
}
// will throw
go.GraphLinksModel.fromJson(json);
</script>
</body>
</html>
The problem is toJson returns a string containing {"keyValues":{""":"\""}}
where the """
is invalid json. It escapes the object’s value fine ("\""
), just doesn’t escape it in the key part.
We’re using version gojs@2.1.50
from npm (and targeting web via webpack), but this happens using the https://gojs.net/latest/release/go.js
url in my example above as well.