Rev 199: Fix a bug in Meliae when you don't have a JSON library. in http://bazaar.launchpad.net/%2Bbranch/meliae

John Arbash Meinel john at arbash-meinel.com
Sun May 19 06:14:05 UTC 2013


At http://bazaar.launchpad.net/%2Bbranch/meliae

------------------------------------------------------------
revno: 199
revision-id: john at arbash-meinel.com-20130519061348-r91e22vhsls2z60j
parent: john at arbash-meinel.com-20130220055708-mmps5b7j9i4v1cfh
author: Martin Pool <mbp at sourcefrog.net>
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: meliae
timestamp: Sun 2013-05-19 07:13:48 +0100
message:
  Fix a bug in Meliae when you don't have a JSON library.
  
  Change it so we can handle when strings embed the " character.
-------------- next part --------------
=== modified file 'meliae/_loader.pyx'
--- a/meliae/_loader.pyx	2013-02-20 05:57:08 +0000
+++ b/meliae/_loader.pyx	2013-05-19 06:13:48 +0000
@@ -581,6 +581,8 @@
             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 = ''

=== modified file 'meliae/loader.py'
--- a/meliae/loader.py	2010-08-09 16:13:08 +0000
+++ b/meliae/loader.py	2013-05-19 06:13:48 +0000
@@ -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'\}')
 

=== modified file 'meliae/tests/test_loader.py'
--- a/meliae/tests/test_loader.py	2010-08-09 16:13:08 +0000
+++ b/meliae/tests/test_loader.py	2013-05-19 06:13:48 +0000
@@ -133,7 +133,7 @@
             '{"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())
@@ -148,10 +148,7 @@
         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)



More information about the bazaar-commits mailing list