Skip to content

Commit d2f3f67

Browse files
committed
Fixing unicode errors with names
1 parent 70bd212 commit d2f3f67

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

sourcemap/decoder.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
:license: BSD, see LICENSE for more details.
1212
"""
1313
import os
14+
import sys
1415
from functools import partial
1516
from .exceptions import SourceMapDecodeError
1617
from .objects import Token, SourceMapIndex
@@ -21,6 +22,10 @@
2122

2223
__all__ = ('SourceMapDecoder',)
2324

25+
# True if we are running on Python 3.
26+
PY3 = sys.version_info[0] == 3
27+
text_type = str if PY3 else unicode
28+
2429

2530
class SourceMapDecoder(object):
2631
def parse_vlq(self, segment):
@@ -105,7 +110,7 @@ def decode(self, source):
105110
smap = json.loads(source)
106111
sources = smap['sources']
107112
sourceRoot = smap.get('sourceRoot')
108-
names = list(map(str, smap['names']))
113+
names = list(map(text_type, smap['names']))
109114
mappings = smap['mappings']
110115
lines = mappings.split(';')
111116

tests/fixtures/unicode.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var ñ = 10;
2+
if (ñ == 5) {
3+
alert('lol');
4+
}

tests/fixtures/unicode.min.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var ñ=10;if(ñ==5){alert("lol")}
2+
/*
3+
//@ sourceMappingURL=tests/fixtures/unicode.min.map
4+
*/

tests/fixtures/unicode.min.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/test_integration.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,9 @@ def test_coolstuff(self):
5959
end = start + len(token.name)
6060
substring = source_line[start:end]
6161
assert token.name == substring
62+
63+
def test_unicode_names(self):
64+
_, _, min_map = self.get_fixtures('unicode')
65+
66+
# This shouldn't blow up
67+
sourcemap.loads(min_map)

0 commit comments

Comments
 (0)