Skip to content

Commit 4801a53

Browse files
refackCommit Bot
authored and
Commit Bot
committed
gyp: update xml string encoding conversion
Bug: nodejs/node-gyp#1203 Change-Id: I30d71a2bb3d4b09e7bd9409c3c45c32bd182d736 Reviewed-on: https://chromium-review.googlesource.com/509632 Commit-Queue: Mark Mentovai <[email protected]> Reviewed-by: Mark Mentovai <[email protected]>
1 parent d61a939 commit 4801a53

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pylib/gyp/easy_xml.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import re
66
import os
7+
import locale
78

89

910
def XmlToString(content, encoding='utf-8', pretty=False):
@@ -116,6 +117,10 @@ def WriteXmlIfChanged(content, path, encoding='utf-8', pretty=False,
116117
if win32 and os.linesep != '\r\n':
117118
xml_string = xml_string.replace('\n', '\r\n')
118119

120+
default_encoding = locale.getdefaultlocale()[1]
121+
if default_encoding and default_encoding.upper() != encoding.upper():
122+
xml_string = xml_string.decode(default_encoding).encode(encoding)
123+
119124
# Get the old content
120125
try:
121126
f = open(path, 'r')

0 commit comments

Comments
 (0)