Skip to content

Commit 380a5a1

Browse files
authored
Fix decode_octal_encoded_utf8() (#24563)
Fix decode_octal_encoded_utf8() to work in scenario where a directory name consists of exactly two digits, i.e. '\\foo\\21\\bar'
1 parent 8cbbec4 commit 380a5a1

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

test/test_other.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10780,8 +10780,10 @@ def test(infile, source_map_added_dir=''):
1078010780

1078110781
test('A ä☃ö Z.cpp')
1078210782

10783-
ensure_dir('inner Z ö☃ä A')
10784-
test('inner Z ö☃ä A/A ä☃ö Z.cpp', 'inner Z ö☃ä A')
10783+
# Explicitly test the case of spaces, UTF-8 chars, and a tricky case of a path consisting
10784+
# of only two digits (that could be confused for an octal escape sequence)
10785+
ensure_dir('inner Z ö☃ä A/21')
10786+
test('inner Z ö☃ä A/21/A ä☃ö Z.cpp', 'inner Z ö☃ä A/21')
1078510787

1078610788
def test_wasm_sourcemap_extract_comp_dir_map(self):
1078710789
wasm_sourcemap = importlib.import_module('tools.wasm-sourcemap')

tools/wasm-sourcemap.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,16 @@ def decode_octal_encoded_utf8(str):
204204
i = 0
205205
o = 0
206206
final_length = len(str)
207+
in_escape = False
207208
while i < len(str):
208-
if str[i] == '\\' and (str[i + 1] == '2' or str[i + 1] == '3'):
209+
if not in_escape and str[i] == '\\' and (str[i + 1] == '2' or str[i + 1] == '3'):
209210
out[o] = int(str[i + 1:i + 4], 8)
210211
i += 4
211212
final_length -= 3
213+
in_escape = False
212214
else:
213215
out[o] = ord(str[i])
216+
in_escape = False if in_escape else (str[i] == '\\')
214217
i += 1
215218
o += 1
216219
return out[:final_length].decode('utf-8')

0 commit comments

Comments
 (0)