Skip to content

Commit

Permalink
gyp: update xml string encoding conversion
Browse files Browse the repository at this point in the history
Bug: nodejs/node-gyp#1203
Change-Id: I30d71a2bb3d4b09e7bd9409c3c45c32bd182d736
  • Loading branch information
refack committed Jul 24, 2017
1 parent a478c1a commit 5a3264c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pylib/gyp/easy_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import re
import os
import locale


def XmlToString(content, encoding='utf-8', pretty=False):
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 5a3264c

Please sign in to comment.