[Pkg-mozext-commits] [adblock-plus] 262/464: Locale processing: Better escaping of data in properties files
David Prévot
taffit at moszumanska.debian.org
Tue Jul 22 20:44:23 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit 9c59fafade67616dd9d4ca36e7d7ca5a1f13a8ce
Author: Wladimir Palant <trev at adblockplus.org>
Date: Wed Jul 4 15:51:43 2012 +0200
Locale processing: Better escaping of data in properties files
---
localeTools.py | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/localeTools.py b/localeTools.py
index 5048dee..d36adb4 100644
--- a/localeTools.py
+++ b/localeTools.py
@@ -56,6 +56,12 @@ def parseDTDString(data, path):
for entry in result:
yield entry
+def escapeProperty(value):
+ return value.replace('\n', '\\n')
+
+def unescapeProperty(value):
+ return value.replace('\\n', '\n')
+
def parsePropertiesString(data, path):
currentComment = None
for line in data.splitlines():
@@ -64,7 +70,7 @@ def parsePropertiesString(data, path):
currentComment = match.group(1)
elif '=' in line:
key, value = line.split('=', 1)
- yield (key, currentComment, value)
+ yield (unescapeProperty(key), currentComment, unescapeProperty(value))
currentComment = None
elif re.search(r'\S', line):
print >>sys.stderr, 'Unrecognized data in file %s: %s' % (path, line)
@@ -92,7 +98,7 @@ def generateStringEntry(key, value, path):
if path.endswith('.dtd'):
return '<!ENTITY %s "%s">\n' % (escapeEntity(key), escapeEntity(value))
else:
- return '%s=%s\n' % (key, value)
+ return '%s=%s\n' % (escapeProperty(key), escapeProperty(value))
def appendToFile(path, key, value):
fileHandle = codecs.open(path, 'ab', encoding='utf-8')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list