masklinn avatar 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

Comments (0)

Files changed (2)

                 } 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;

test/builtins/str.js

             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 () {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.