From af94d8ff5e08d103bcebef65a052990ef819af0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20B=C3=A4ume?= Date: Mon, 23 Jun 2014 12:17:40 +0200 Subject: [PATCH] restore previous behaviour with \n in strings An incompatible change (that actually breaks po parsing after writing) had been introduced with commit e164fcfe9d6f28cd3d452f4de274a41663160cef. If _process returned an array (which is the case for strings containing \n character), array.toString will return a comma separated list, which is not valid po syntax. Added a test to restore the behaviour from before the e164fcfe9d6f28cd3d452f4de274a41663160cef. --- lib/po.js | 3 ++- test/write.js | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/po.js b/lib/po.js index 06c61fd..e22db97 100644 --- a/lib/po.js +++ b/lib/po.js @@ -261,7 +261,8 @@ PO.Item.prototype.toString = function () { }); } else { text = isArray(text) ? text.join() : text; - lines = lines.concat(mkObsolete + _process(keyword, text)); + var processed = _process(keyword, text); + lines = lines.concat(mkObsolete + processed.join('\n' + mkObsolete)); } } }); diff --git a/test/write.js b/test/write.js index d982b3a..dd319ad 100644 --- a/test/write.js +++ b/test/write.js @@ -92,6 +92,15 @@ describe('Write', function () { assertHasLine(item.toString(), 'msgid "\\\\ should be written escaped"'); }); + it('should escape \\n', function () { + var item = new PO.Item(); + + item.msgid = '\n should be written escaped'; + assertHasLine(item.toString(), 'msgid ""'); + assertHasLine(item.toString(), '""'); + assertHasLine(item.toString(), '" should be written escaped"'); + }); + it('should write identical file after parsing a file', function () { var input = fs.readFileSync(__dirname + '/fixtures/c-strings.po', 'utf8'); var po = PO.parse(input);