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
Reviewed-on: https://chromium-review.googlesource.com/509632
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
  • Loading branch information
refack authored and Commit Bot committed Jul 24, 2017
1 parent d61a939 commit 4801a53
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 4801a53

Please sign in to comment.