From d5af7a2d241fe7127646e8a761064f8c0e605c0c Mon Sep 17 00:00:00 2001 From: Mark Weaver Date: Thu, 21 Jun 2018 15:53:46 +0100 Subject: [PATCH] handle crlf --- fluent-syntax/src/stream.js | 5 +++-- fluent-syntax/test/behavior_test.js | 2 ++ fluent/src/parser.js | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fluent-syntax/src/stream.js b/fluent-syntax/src/stream.js index 0eb281c5f..8de4ce2aa 100644 --- a/fluent-syntax/src/stream.js +++ b/fluent-syntax/src/stream.js @@ -1,7 +1,8 @@ export class ParserStream { constructor(string) { - this.string = string; - this.iter = string[Symbol.iterator](); + this.string = string.indexOf("\r") !== -1 ? + string.replace(/(?:\r\n)/g, "\n") : string; + this.iter = this.string[Symbol.iterator](); this.buf = []; this.peekIndex = 0; this.index = 0; diff --git a/fluent-syntax/test/behavior_test.js b/fluent-syntax/test/behavior_test.js index 3838ded53..9e75fee55 100644 --- a/fluent-syntax/test/behavior_test.js +++ b/fluent-syntax/test/behavior_test.js @@ -72,6 +72,8 @@ readdir(fixtures, function(err, filenames) { const filepath = join(fixtures, filename); test(filename, function() { return readfile(filepath).then(file => { + file = file.indexOf("\r") !== -1 ? + file.replace(/(?:\r\n)/g, "\n") : file; const { directives, source } = preprocess(file); const expected = directives.join('\n') + '\n'; const ast = parse(source); diff --git a/fluent/src/parser.js b/fluent/src/parser.js index e356e36f5..e3172f3a6 100644 --- a/fluent/src/parser.js +++ b/fluent/src/parser.js @@ -30,7 +30,8 @@ class RuntimeParser { * @returns {Array} */ getResource(string) { - this._source = string; + this._source = string.indexOf("\r") !== -1 ? + string.replace(/(?:\r\n)/g, "\n") : string; this._index = 0; this._length = string.length; this.entries = {};