From 13219cebcb11f95fdaa77af653e96ac42e7e6dcc Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Mon, 5 Jan 2015 12:14:42 +0200 Subject: Fix handling \r\n Close #437 --- lib/parse.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/parse.js') diff --git a/lib/parse.js b/lib/parse.js index 931e5f66..c3f0822c 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -206,7 +206,7 @@ var EX_EOF = {}; function tokenizer($TEXT, filename, html5_comments) { var S = { - text : $TEXT.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/\uFEFF/g, ''), + text : $TEXT.replace(/\uFEFF/g, ''), filename : filename, pos : 0, tokpos : 0, @@ -225,10 +225,15 @@ function tokenizer($TEXT, filename, html5_comments) { var ch = S.text.charAt(S.pos++); if (signal_eof && !ch) throw EX_EOF; - if (ch == "\n") { + if ("\r\n\u2028\u2029".indexOf(ch) >= 0) { S.newline_before = S.newline_before || !in_string; ++S.line; S.col = 0; + if (!in_string && ch == "\r" && peek() == "\n") { + // treat a \r\n sequence as a single \n + ++S.pos; + ch = "\n"; + } } else { ++S.col; } -- cgit v1.2.3