From 5a3264c5c8bca3d3e16266a48653de49385acd76 Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Mon, 24 Jul 2017 08:50:51 -0400 Subject: [PATCH] gyp: update xml string encoding conversion Bug: https://github.com/nodejs/node-gyp/pull/1203 Change-Id: I30d71a2bb3d4b09e7bd9409c3c45c32bd182d736 --- pylib/gyp/easy_xml.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pylib/gyp/easy_xml.py b/pylib/gyp/easy_xml.py index bf949b6a..2522efb2 100644 --- a/pylib/gyp/easy_xml.py +++ b/pylib/gyp/easy_xml.py @@ -4,6 +4,7 @@ import re import os +import locale def XmlToString(content, encoding='utf-8', pretty=False): @@ -116,6 +117,10 @@ def WriteXmlIfChanged(content, path, encoding='utf-8', pretty=False, if win32 and os.linesep != '\r\n': xml_string = xml_string.replace('\n', '\r\n') + default_encoding = locale.getdefaultlocale()[1] + if default_encoding and default_encoding.upper() != encoding.upper(): + xml_string = xml_string.decode(default_encoding).encode(encoding) + # Get the old content try: f = open(path, 'r')