From b7f79a0abbecd360dec8b9bf0248411cb0984b46 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 10 Jul 2010 16:31:27 -0400 Subject: [PATCH] Fixing issues where block comments not starting with whitespace would gobble up piles of code. Test case added. Fixes #8 --- models/js_file.php | 2 +- tests/cases/models/js_file.test.php | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/models/js_file.php b/models/js_file.php index 347d58d0..246915cc 100644 --- a/models/js_file.php +++ b/models/js_file.php @@ -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)) { diff --git a/tests/cases/models/js_file.test.php b/tests/cases/models/js_file.test.php index 554cd9ce..e5ad5824 100644 --- a/tests/cases/models/js_file.test.php +++ b/tests/cases/models/js_file.test.php @@ -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 = <<assertEqual($expected, $result); + } + /** * test that js files cache correctly. *