Support multiple spaces after msgid

This commit is contained in:
Remko Tronçon 2021-12-01 09:48:24 +01:00
parent ff1b888af1
commit 685be92923
5 changed files with 31 additions and 3 deletions

2
dist/pofile.js vendored
View File

@ -83,7 +83,7 @@ PO.parse = function (data) {
var headers = [];
//everything until the first 'msgid ""' is considered header
while (sections[0] && (headers.length === 0 || headers[headers.length - 1].indexOf('msgid ""') < 0)) {
if (sections[0].match(/msgid "[^"]/)) {
if (sections[0].match(/msgid\s+"[^"]/)) {
//found first real string, adding a dummy header item
headers.push('msgid ""');
} else {

2
dist/pofile.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -80,7 +80,7 @@ PO.parse = function (data) {
var headers = [];
//everything until the first 'msgid ""' is considered header
while (sections[0] && (headers.length === 0 || headers[headers.length - 1].indexOf('msgid ""') < 0)) {
if (sections[0].match(/msgid "[^"]/)) {
if (sections[0].match(/msgid\s+"[^"]/)) {
//found first real string, adding a dummy header item
headers.push('msgid ""');
} else {

View File

@ -0,0 +1,8 @@
# some comment
msgid "First id, no header"
msgstr ""
msgid "A second string"
msgstr ""

View File

@ -70,4 +70,24 @@ describe('PO files with no headers', function () {
assert.equal(po.items.length, 2);
});
});
describe('advanced example with extra spaces', function () {
var po;
before(function (done) {
PO.load(__dirname + '/fixtures/no_header_extra_spaces.po', function (err, result) {
assert.equal(err, null);
po = result;
done();
});
});
it('Parses the po file', function () {
assert.notEqual(po, null);
});
it('Finds all items', function () {
assert.equal(po.items.length, 2);
});
});
});