diff --git a/artiq/protocols/pyon.py b/artiq/protocols/pyon.py index 8c4afbbdc..238ff2198 100644 --- a/artiq/protocols/pyon.py +++ b/artiq/protocols/pyon.py @@ -74,7 +74,10 @@ class _Encoder: def encode_str(self, x): # Do not use repr() for JSON compatibility. - tt = {ord("\""): "\\\"", ord("\\"): "\\\\", ord("\n"): "\\n"} + tt = { + ord("\""): "\\\"", ord("\\"): "\\\\", + ord("\n"): "\\n", ord("\r"): "\\r" + } return "\"" + x.translate(tt) + "\"" def encode_bytes(self, x): diff --git a/artiq/test/serialization.py b/artiq/test/serialization.py index 7bcbed5eb..88cf9b18e 100644 --- a/artiq/test/serialization.py +++ b/artiq/test/serialization.py @@ -26,7 +26,7 @@ class PYON(unittest.TestCase): _json_test_object = { "a": "b", "x": [1, 2, {}], - "foo\nbaz\\qux\"": ["bar", 1.2, {"x": "y"}], + "foo\nbaz\\qux\"\r2": ["bar", 1.2, {"x": "y"}], "bar": [True, False, None] }