Skip to content

Commit 458d472

Browse files
committed
Properly escape strings.
Backported from decompyle3
1 parent 3b1d5bd commit 458d472

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

uncompyle6/semantics/customize36.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019-2023 by Rocky Bernstein
1+
# Copyright (c) 2019-2024 by Rocky Bernstein
22
#
33
# This program is free software: you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -15,16 +15,17 @@
1515
"""Isolate Python 3.6 version-specific semantic actions here.
1616
"""
1717

18-
from xdis import iscode
1918
from spark_parser.ast import GenericASTTraversalPruningException
19+
from xdis import iscode
20+
2021
from uncompyle6.scanners.tok import Token
21-
from uncompyle6.semantics.helper import flatten_list, escape_string, strip_quotes
2222
from uncompyle6.semantics.consts import (
2323
INDENT_PER_LEVEL,
2424
PRECEDENCE,
2525
TABLE_DIRECT,
2626
TABLE_R,
2727
)
28+
from uncompyle6.semantics.helper import escape_string, flatten_list, strip_quotes
2829
from uncompyle6.util import get_code_name
2930

3031

@@ -38,7 +39,6 @@ def escape_format(s):
3839

3940

4041
def customize_for_version36(self, version):
41-
4242
# fmt: off
4343
PRECEDENCE["call_kw"] = 0
4444
PRECEDENCE["call_kw36"] = 1
@@ -276,7 +276,7 @@ def call_ex_kw(node):
276276
if value == "":
277277
fmt = "%c(%p)"
278278
else:
279-
fmt = "%%c(%s, %%p)" % value
279+
fmt = "%c" + ("(%s, " % value).replace("%", "%%") + "%p)"
280280

281281
self.template_engine(
282282
(fmt, (0, "expr"), (2, "build_map_unpack_with_call", 100)), node
@@ -295,7 +295,7 @@ def call_ex_kw2(node):
295295
if value == "":
296296
fmt = "%c(%p)"
297297
else:
298-
fmt = "%%c(%s, %%p)" % value
298+
fmt = "%c" + ("(%s, " % value).replace("%", "%%") + "%p)"
299299

300300
self.template_engine(
301301
(fmt, (0, "expr"), (2, "build_map_unpack_with_call", 100)), node
@@ -707,6 +707,7 @@ def n_list_comp_async(node):
707707
self.comprehension_walk_newer(node, iter_index=3, code_index=0)
708708
self.write("]")
709709
self.prune()
710+
710711
self.n_list_comp_async = n_list_comp_async
711712

712713
# def kwargs_only_36(node):

0 commit comments

Comments
 (0)