Skip to content

Commit 13be2c9

Browse files
author
Alex Petty
committed
add test for .po files with no header
1 parent 2ba0779 commit 13be2c9

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

lib/parse.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ module.exports = function(buffer, options) {
6666
});
6767

6868
// Attach headers (overwrites any empty translation keys that may have somehow gotten in)
69-
result[''] = parsed.headers;
69+
if (parsed.headers) {
70+
result[''] = parsed.headers;
71+
}
7072

7173
if (options.format === 'mf') {
7274
delete result[''];

test/fixtures/en-no-header.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"Hello World": [
3+
null,
4+
"Hello World"
5+
]
6+
}

test/fixtures/en-no-header.po

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Very minimal .po
2+
3+
msgid "Hello World"
4+
msgstr "Hello World"

test/po2json_test.js

+14
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,17 @@ module.exports["parse with Plural-Forms == nplurals=1; plural=0;"] = {
128128
test.done();
129129
}
130130
}
131+
132+
module.exports["parse with no headers"] ={
133+
setUp: function(callback){
134+
this.po = fs.readFileSync(__dirname + "/fixtures/en-no-header.po");
135+
this.json = JSON.parse(fs.readFileSync(__dirname + "/fixtures/en-no-header.json", "utf-8"));
136+
callback();
137+
},
138+
139+
parse: function(test){
140+
var parsed = po2json.parse(this.po);
141+
test.deepEqual(parsed, this.json);
142+
test.done();
143+
}
144+
}

0 commit comments

Comments
 (0)