Skip to content

Commit

Permalink
Move line-feed normalization, to only affect code files, not file imp…
Browse files Browse the repository at this point in the history
…orts

Fixes issue #139
  • Loading branch information
matthiasmullie committed Oct 27, 2016
1 parent 622e61c commit 1a6cb6b
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function add($data /* $data = null, ... */)
$value = $this->load($data);
$key = ($data != $value) ? $data : count($this->data);

// replace CR linefeeds etc.
// @see https://github.com/matthiasmullie/minify/pull/139
$value = str_replace(array("\r\n", "\r"), "\n", $value);

// store data
$this->data[$key] = $value;
}
Expand Down Expand Up @@ -159,9 +163,6 @@ protected function load($data)
if ($this->canImportFile($data)) {
$data = file_get_contents($data);

// replace CR linefeeds etc.
$data = preg_replace('~\R~', "\n", $data);

// strip BOM, if any
if (substr($data, 0, 3) == "\xef\xbb\xbf") {
$data = substr($data, 3);
Expand Down
14 changes: 14 additions & 0 deletions tests/css/CSSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,20 @@ public function dataProvider()
'p{width:calc(35% + (10% + 10%))}',
);

// https://github.com/matthiasmullie/minify/issues/139
$tests[] = array(
__DIR__.'/sample/line_endings/lf/parent.css',
'p{color:green}body{color:red}',
);
$tests[] = array(
__DIR__.'/sample/line_endings/cr/parent.css',
'p{color:green}body{color:red}',
);
$tests[] = array(
__DIR__.'/sample/line_endings/crlf/parent.css',
'p{color:green}body{color:red}',
);

return $tests;
}

Expand Down
1 change: 1 addition & 0 deletions tests/css/sample/line_endings/cr/import.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* set p color*/p { color: green;}
Expand Down
1 change: 1 addition & 0 deletions tests/css/sample/line_endings/cr/parent.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* import some file */@import "import.css";/* set body color */body { color: red;}
Expand Down
1 change: 1 addition & 0 deletions tests/css/sample/line_endings/crlf/import.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* set p color*/p { color: green;}
Expand Down
7 changes: 7 additions & 0 deletions tests/css/sample/line_endings/crlf/parent.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* import some file */
@import "import.css";

/* set body color */
body {
color: red;
}
4 changes: 4 additions & 0 deletions tests/css/sample/line_endings/lf/import.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* set p color*/
p {
color: green;
}
7 changes: 7 additions & 0 deletions tests/css/sample/line_endings/lf/parent.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* import some file */
@import "import.css";

/* set body color */
body {
color: red;
}
14 changes: 14 additions & 0 deletions tests/js/JSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,20 @@ function otherFuncName() {
'matchers.push(/^[0-9]*$/.source);String(dateString).match(/^[0-9]*$/)',
);

// https://github.com/matthiasmullie/minify/issues/139
$tests[] = array(
__DIR__.'/sample/line_endings/lf/script.js',
'var a=1',
);
$tests[] = array(
__DIR__.'/sample/line_endings/cr/script.js',
'var a=1',
);
$tests[] = array(
__DIR__.'/sample/line_endings/crlf/script.js',
'var a=1',
);

// update tests' expected results for cross-system compatibility
foreach ($tests as &$test) {
if (!empty($test[1])) {
Expand Down
1 change: 1 addition & 0 deletions tests/js/sample/line_endings/cr/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// nothing special herevar a = 1;
Expand Down
1 change: 1 addition & 0 deletions tests/js/sample/line_endings/crlf/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// nothing special herevar a = 1;
Expand Down
2 changes: 2 additions & 0 deletions tests/js/sample/line_endings/lf/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// nothing special here
var a = 1;

0 comments on commit 1a6cb6b

Please sign in to comment.