Skip to content

Commit

Permalink
[[FIX]] (cli - extract) lines can end with "\\r\\n", not "\\n\\r"
Browse files Browse the repository at this point in the history
Fixes gh-2825
  • Loading branch information
nicolo-ribaudo authored and jugglinmike committed Mar 26, 2016
1 parent 351e8f3 commit 93818f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function extract(code, when) {
// in between the last </script> tag and this <script> tag to preserve
// location information.
inscript = true;
js.push.apply(js, code.slice(index, parser.endIndex).match(/\n\r|\n|\r/g));
js.push.apply(js, code.slice(index, parser.endIndex).match(/\r\n|\n|\r/g));
startOffset = null;
}

Expand All @@ -297,7 +297,7 @@ function extract(code, when) {
if (!inscript)
return;

var lines = data.split(/\n\r|\n|\r/);
var lines = data.split(/\r\n|\n|\r/);

if (!startOffset) {
lines.some(function(line) {
Expand Down Expand Up @@ -362,7 +362,7 @@ function extractOffsets(code, when) {
// location information.
inscript = true;
var fragment = code.slice(index, parser.endIndex);
var n = (fragment.match(/\n\r|\n|\r/g) || []).length;
var n = (fragment.match(/\r\n|\n|\r/g) || []).length;
lineCounter += n;
startOffset = null;
}
Expand All @@ -380,7 +380,7 @@ function extractOffsets(code, when) {
if (!inscript)
return;

var lines = data.split(/\n\r|\n|\r/);
var lines = data.split(/\r\n|\n|\r/);

if (!startOffset) {
lines.some(function(line) {
Expand Down
14 changes: 14 additions & 0 deletions tests/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,20 @@ exports.extract = {

test.equal(cli.extract(html, "auto"), js);

test.done();
},

"\\r\\n as line terminator (gh-2825)": function (test) {
var html = [
"<script>",
" var a = 3;",
"</script>"
].join("\r\n");

var js = "\nvar a = 3;\n";

test.equal(cli.extract(html, "auto"), js);

test.done();
}
};
Expand Down

0 comments on commit 93818f3

Please sign in to comment.