Browse files

Sometimes whitespace after HEREDOC is significant, when the next toke…

…n is not semi-colon don't strip whitespace
  • Loading branch information...
1 parent 070b58c commit e11d1917146f994681cd8e5c9926cc753a0fb430 Keith Minkler committed Jul 28, 2010
Showing with 40 additions and 4 deletions.
  1. +10 −1 Beautifier.php
  2. +29 −2 tests/BeautifierBugsTest.php
  3. +1 −1 tests/Helpers.php
View
11 Beautifier.php
@@ -281,6 +281,9 @@ public function __construct()
$this->aTokenNames[constant($sToken) ] = $sToken;
$this->aTokenFunctions[constant($sToken) ] = $sToken;
}
+ if (!defined('T_NAMESPACE')) { // like pre 5.3.0
+ define('T_NAMESPACE', 377);
+ }
$aTokensToChange = array(
/* QUOTES */
'"' => "T_DOUBLE_QUOTE",
@@ -1191,7 +1194,11 @@ private function pushControlSeq($aToken)
private function popControlSeq()
{
$aEl = array_pop($this->aControlSeq);
- $this->oLog->log('Pop Control:' . $this->getTokenName($aEl), PEAR_LOG_DEBUG);
+ if ($aEl) {
+ $this->oLog->log('Pop Control:' . $this->getTokenName($aEl) , PEAR_LOG_DEBUG);
+ } else {
+ $this->oLog->log('Pop Unknown Control', PEAR_LOG_DEBUG);
+ }
return $aEl;
}
/**
@@ -1762,6 +1769,8 @@ public function removeWhitespace()
//
if ($this->isPreviousTokenConstant(T_COMMENT) and preg_match("/^(\/\/|#)/", $this->getPreviousTokenContent())) { // Here for short comment
return false;
+ } elseif ($this->isPreviousTokenConstant(T_END_HEREDOC) && $this->getToken($this->iCount) != ';') {
+ return false;
} elseif ($this->getPreviousTokenConstant(2) == T_END_HEREDOC) { // And here for heredoc
return false;
}
View
31 tests/BeautifierBugsTest.php
@@ -60,6 +60,33 @@ function testBugInternal1()
$this->assertEquals($sExpected, $this->oBeaut->get());
}
/**
+ * HEREDOC before parenthesis
+ * Close tag after heredoc remove whitespace,
+ * breaking the script.
+ *
+ */
+ function testBugHEREDOCparen()
+ {
+ $sText = <<<SCRIPT
+<?php
+\$a = someFunction(<<<HEREDOC
+sdsdsds
+HEREDOC
+);
+?>
+SCRIPT;
+ $this->setText($sText);
+ $sExpected = <<<SCRIPT
+<?php
+\$a = someFunction(<<<HEREDOC
+sdsdsds
+HEREDOC
+);
+?>
+SCRIPT;
+ $this->assertEquals($sExpected, $this->oBeaut->get());
+ }
+ /**
* Bug 1597
* Brace after short comment in new line was appended to
* the comment, breaking the code
@@ -1074,7 +1101,7 @@ function testBug14396() {
*/
function testBug14537() {
- if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
+ if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
$sText = <<<SCRIPT
<?php
@@ -1135,4 +1162,4 @@ class Z {
}
}
-?>
+?>
View
2 tests/Helpers.php
@@ -3,7 +3,7 @@
# use pear or local version of php_beautifier
if (file_exists(dirname(__FILE__).'/../Beautifier.php')) {
- include_once dirname(__FILE).'/../Beautifier.php';
+ include_once dirname(__FILE__).'/../Beautifier.php';
} else {
include_once "PHP/Beautifier.php";
}

0 comments on commit e11d191

Please sign in to comment.