Skip to content

Commit

Permalink
Fix a bug in Meliae when you don't have a JSON library.
Browse files Browse the repository at this point in the history
Change it so we can handle when strings embed the " character.
  • Loading branch information
sourcefrog authored and jameinel committed May 19, 2013
1 parent a42f662 commit da37f2e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 2 additions & 0 deletions meliae/_loader.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ cdef class _MemObjectProxy:
else:
# TODO: This isn't perfect, as it doesn't do proper json
# escaping
if '"' in self.value:
raise AssertionError(self.value)
value = '"value": "%s", ' % self.value
else:
value = ''
Expand Down
2 changes: 1 addition & 1 deletion meliae/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
r', "size": (?P<size>\d+)'
r'(, "name": "(?P<name>.*)")?'
r'(, "len": (?P<len>\d+))?'
r'(, "value": "?(?P<value>.*)"?)?'
r'(, "value": (?P<valuequote>"?)(?P<value>.*)(?P=valuequote))?'
r', "refs": \[(?P<refs>[^]]*)\]'
r'\}')

Expand Down
7 changes: 2 additions & 5 deletions meliae/tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_load_without_simplejson(self):
'{"address": 2345, "type": "module", "size": 60, "name": "mymod"'
', "refs": [1234]}',
'{"address": 4567, "type": "str", "size": 150, "len": 126'
', "value": "Test \\\'whoami\\\'\\u000a\\"Your name\\"'
', "value": "Test \\\'whoami\\\'\\u000a\\"Your name\\""'
', "refs": []}'
], using_json=False, show_prog=False).objs
keys = sorted(objs.keys())
Expand All @@ -148,10 +148,7 @@ def test_load_without_simplejson(self):
self.assertEqual("module", obj.type_str)
self.assertEqual("mymod", obj.value)
obj = objs[4567]
# Known failure? We don't unescape properly, also, I'm surprised this
# works. " should exit the " string, but \" seems to leave it. But the
# '\' is also left verbatim because it is a raw string...
self.assertEqual(r"Test \'whoami\'\u000a\"Your name\"", obj.value)
self.assertEqual("Test \\'whoami\\'\\u000a\\\"Your name\\\"", obj.value)

def test_load_example(self):
objs = loader.load(_example_dump, show_prog=False)
Expand Down

0 comments on commit da37f2e

Please sign in to comment.