Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Bug 1306602 - FTL parser does not handle Windows end of line ('\r\n') #151

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions src/ftl/entries/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,25 @@ class EntriesParser {
cc = this._source.charCodeAt(++this._index);
}
}

isEOL() {
return this._source[this._index] == '\n' || (this._source[this._index] == "\r" && this._source[this._index+1] == "\n");
}

getLineContent() {
let start = this._index;
let eol = this._source.indexOf('\n', this._index);
if (eol === -1) {
eol = this._length;
}
this._index = eol;
let eoc = (eol > 0 && this._source.charCodeAt(eol-1) === 13) ? eol-1 : eol;
if(start != eoc) {
return this._source.slice(start, eoc);
} else {
return undefined;
}
}

getIdentifier() {
const start = this._index;
Expand Down Expand Up @@ -261,22 +280,13 @@ class EntriesParser {
if (this._source[start] === '"') {
return this.getComplexPattern();
}
let eol = this._source.indexOf('\n', this._index);

if (eol === -1) {
eol = this._length;
}

const line = start !== eol ?
this._source.slice(start, eol) : undefined;

const line = this.getLineContent();
if (line !== undefined && line.includes('{')) {
this._index = start;
return this.getComplexPattern();
}

this._index = eol + 1;

this.getLineWS();
this.getWS();

if (this._source[this._index] === '|') {
this._index = start;
Expand Down Expand Up @@ -320,7 +330,12 @@ class EntriesParser {
while (this._index < this._length) {
// This block handles multi-line strings combining strings seaprated
// by new line and `|` character at the beginning of the next one.
if (ch === '\n') {
if(ch == '\r') {
// Ignore it
this._index++;
ch = this._source[this._index];
continue;
} else if (ch === '\n') {
if (quoteDelimited) {
throw this.error('Unclosed string');
}
Expand Down Expand Up @@ -444,7 +459,7 @@ class EntriesParser {

this.getLineWS();

if (this._source[this._index] !== '\n') {
if (!this.isEOL()) {
throw this.error('Members should be listed in a new line');
}

Expand Down