Skip to content

Commit

Permalink
Fixed #24638569: pdepend crashes on vanilia drupal site
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelpichler committed Feb 8, 2012
1 parent 97189b0 commit f20f40a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/php/PHP/Depend.php
Expand Up @@ -547,7 +547,7 @@ private function _performParseProcess()
$this->_builder,
$this->_cacheFactory->create()
);
$parser->setMaxNestingLevel(1024);
$parser->setMaxNestingLevel($this->configuration->parser->nesting);

// Disable annotation parsing?
if ($this->_withoutAnnotations === true) {
Expand Down Expand Up @@ -582,7 +582,7 @@ private function _performAnalyzeProcess()

$this->fireStartAnalyzeProcess();

ini_set('xdebug.max_nesting_level', 1024);
ini_set('xdebug.max_nesting_level', $this->configuration->parser->nesting);

foreach ($analyzerLoader as $analyzer) {
// Add filters if this analyzer is filter aware
Expand Down
3 changes: 3 additions & 0 deletions src/main/php/PHP/Depend/Util/Configuration/Factory.php
Expand Up @@ -103,6 +103,9 @@ public function __construct()
$this->default->imageConvert = new stdClass();
$this->default->imageConvert->fontSize = '11';
$this->default->imageConvert->fontFamily = 'Arial';

$this->default->parser = new stdClass();
$this->default->parser->nesting = 8192;
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/main/php/PHP/Depend/Util/Configuration/Parser.php
Expand Up @@ -109,6 +109,7 @@ public function parse($file)
$this->sxml = new SimpleXMLElement($file, null, true);

$this->parseCache();
$this->parseParser();
$this->parseImageConvert();

return $this->settings;
Expand Down Expand Up @@ -145,4 +146,17 @@ protected function parseImageConvert()
= (float) $this->sxml->imageConvert->fontSize;
}
}

/**
* This method parses the parser related configuration settings.
*
* @return void
* @since 1.0.1
*/
protected function parseParser()
{
if (isset($this->sxml->parser->nesting)) {
$this->settings->parser->nesting = (int) $this->sxml->parser->nesting;
}
}
}
5 changes: 4 additions & 1 deletion src/site/docx/changes.xml
Expand Up @@ -13,9 +13,12 @@
date="2012/02/08"
description="This release fixes two bugs in PHP_Depend's
parser, which resulted in uncatchable errors.">
<action date="" dev="mapi" issue="24635313" system="pivotaltracker" type="fix">
<action date="97189b0" dev="mapi" issue="24635313" system="pivotaltracker" type="fix" due-to="Rex Mcconnell">
_parseOptionalExpression() returning null causes exception
</action>
<action date="" dev="mapi" issue="24638569" system="pivotaltracker" type="fix" due-to="bluszcz">
pdepend crashes on vanilia drupal site
</action>
</release>

<release version="1.0.0"
Expand Down
13 changes: 13 additions & 0 deletions src/test/php/PHP/Depend/Util/Configuration/FactoryTest.php
Expand Up @@ -203,6 +203,19 @@ public function testCreateDefaultOverwritesSettingsWithValuesDefinedInXmlAndXmlD
self::assertEquals(42, $config->imageConvert->fontSize);
}

/**
* testDefaultConfigurationHasExpectedParserNesting
*
* @return void
*/
public function testDefaultConfigurationHasExpectedParserNesting()
{
$factory = new PHP_Depend_Util_Configuration_Factory();
$config = $factory->createDefault();

self::assertEquals(8192, $config->parser->nesting);
}

/**
* testCreateForNotExistingFileThrowsExpectedException
*
Expand Down
16 changes: 16 additions & 0 deletions src/test/php/PHP/Depend/Util/Configuration/ParserTest.php
Expand Up @@ -133,6 +133,19 @@ public function testParserHandlesImagickFontSizeConfigurationValue()
self::assertEquals(23, $values->imageConvert->fontSize);
}

/**
* testParserHandlesParserNestingConfigurationValue
*
* @return void
*/
public function testParserHandlesParserNestingConfigurationValue()
{
$parser = new PHP_Depend_Util_Configuration_Parser($this->createFixture());
$values = $parser->parse($this->getTestConfiguration('pdepend.xml'));

self::assertEquals(423, $values->parser->nesting);
}

/**
* testParserModifiesConfigurationAdaptive
*
Expand Down Expand Up @@ -191,6 +204,9 @@ protected function createFixture()
"imageConvert": {
"fontFamily": "Arial",
"fontSize": 42
},
"parser": {
"nesting": 4096
}
}'
);
Expand Down
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://pdepend.org/schema/configuration"
xsi:schemaLocation="http://pdepend.org/schema/configuration http://pdepend.org/schema/1.0/configuration.xsd">

<parser>
<nesting>423</nesting>
</parser>
</configuration>

0 comments on commit f20f40a

Please sign in to comment.