Skip to content

Commit cb7b53c

Browse files
fix: decode string to string
github-close-issue: 2505
1 parent b1119d5 commit cb7b53c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

gyp/pylib/gyp/easy_xml.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False, win32=False
122122

123123
default_encoding = locale.getdefaultlocale()[1]
124124
if default_encoding and default_encoding.upper() != encoding.upper():
125-
if sys.platform == "win32" and sys.version_info < (3, 7):
126-
xml_string = xml_string.decode("cp1251").encode(encoding)
127-
else:
128-
xml_string = xml_string.encode(encoding)
125+
if sys.platform == "win32":
126+
if isinstance(xml_string, str):
127+
xml_string = xml_string.decode("cp1251") # str --> bytes
128+
xml_string = xml_string.encode(encoding) # bytes --> str
129129

130130
# Get the old content
131131
try:

0 commit comments

Comments
 (0)