Skip to content

Commit

Permalink
Fixing issues where block comments not starting with whitespace would…
Browse files Browse the repository at this point in the history
… gobble up piles of code. Test case added. Fixes #8
  • Loading branch information
markstory committed Jul 10, 2010
1 parent 601a950 commit b7f79a0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion models/js_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function _stripComments($line) {
$inlineComment = '#^\s*//.*$#s';
$blockCommentLine = '#^\s*/\*+.*\*+/#s';
$blockCommentStart = '#^\s*/\*+(?!!).*#s';
$blockCommentEnd = '#^\s*\*+/.*#s';
$blockCommentEnd = '#^.*\*+/.*#s';

if ($this->_inCommentBlock) {
if (preg_match($blockCommentEnd, $line)) {
Expand Down
24 changes: 24 additions & 0 deletions tests/cases/models/js_file.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,30 @@ function test(thing) {
$this->assertEqual($result, $expected);
}

/**
* try removing poorly formatted comments.
*
* @return void
*/
function testPoorlyFormattedCommentRemoval() {
$this->JsFile->settings['stripComments'] = true;
$this->JsFile->settings['searchPaths'] = array(
$this->_pluginPath . 'tests' . DS . 'test_files' . DS . 'js' . DS,
);
$result = $this->JsFile->process('BadComments');
$expected = <<<TEXT
(function($){function Foo(){this.bar=[];}})
function something() {
return 1 + 1;
}
function two() {
return 1 + 1;
}
TEXT;
$this->assertEqual($expected, $result);
}

/**
* test that js files cache correctly.
*
Expand Down

0 comments on commit b7f79a0

Please sign in to comment.