1. masklinn
  2. py.js

Commits

masklinn  committed 2b62048

Fix tokenizer for empty single-quoted strings: treating match group as boolean meant empty strings were falsified and the value was set to undefined

alternative: add a third or-ed clause to an empty string, but being strict on matching is probably better

  • Participants
  • Parent commits ccf62e5
  • Branches default

Comments (0)

Files changed (2)

File lib/py.js

View file
                 } else if (string_pattern.test(token)) {
                     var m = string_pattern.exec(token);
                     tokens.push(create(symbols['(string)'], {
-                        value: m[2] || m[3]
+                        value: (m[2] !== undefined ? m[2] : m[3])
                     }));
                 } else if (token in symbols) {
                     var symbol;

File test/builtins/str.js

View file
             expect(py.eval('"somestring"')).to.be('somestring');
             expect(py.eval("'somestring'")).to.be('somestring');
         });
-
+        it("should correctly handle empty strings", function () {
+            expect(py.eval('""')).to.be('');
+            expect(py.eval('u""')).to.be('');
+            expect(py.eval("''")).to.be('');
+            expect(py.eval("u''")).to.be('');
+        });
     });
     describe('Convert from JS', function () {
         it('should produce a py.str', function () {