diff --git a/lib/parse.js b/lib/parse.js index 91b589d..06139b2 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -66,7 +66,9 @@ module.exports = function(buffer, options) { }); // Attach headers (overwrites any empty translation keys that may have somehow gotten in) - result[''] = parsed.headers; + if (parsed.headers) { + result[''] = parsed.headers; + } if (options.format === 'mf') { delete result['']; diff --git a/test/fixtures/en-no-header.json b/test/fixtures/en-no-header.json new file mode 100644 index 0000000..f933eb8 --- /dev/null +++ b/test/fixtures/en-no-header.json @@ -0,0 +1,6 @@ +{ + "Hello World": [ + null, + "Hello World" + ] +} \ No newline at end of file diff --git a/test/fixtures/en-no-header.po b/test/fixtures/en-no-header.po new file mode 100644 index 0000000..7b57ae1 --- /dev/null +++ b/test/fixtures/en-no-header.po @@ -0,0 +1,4 @@ +# Very minimal .po + +msgid "Hello World" +msgstr "Hello World" diff --git a/test/po2json_test.js b/test/po2json_test.js index 6fba079..1838527 100644 --- a/test/po2json_test.js +++ b/test/po2json_test.js @@ -128,3 +128,17 @@ module.exports["parse with Plural-Forms == nplurals=1; plural=0;"] = { test.done(); } } + +module.exports["parse with no headers"] ={ + setUp: function(callback){ + this.po = fs.readFileSync(__dirname + "/fixtures/en-no-header.po"); + this.json = JSON.parse(fs.readFileSync(__dirname + "/fixtures/en-no-header.json", "utf-8")); + callback(); + }, + + parse: function(test){ + var parsed = po2json.parse(this.po); + test.deepEqual(parsed, this.json); + test.done(); + } +}