Skip to content

Commit

Permalink
Fixes phingofficial#854 - only treat comment as comment if there is a…
Browse files Browse the repository at this point in the history
… space before the delimiter
  • Loading branch information
mrook committed Apr 3, 2012
1 parent 1d0f82f commit 6163ba5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion classes/phing/system/util/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function parse($filePath) {

foreach($lines as $line) {
// strip comments and leading/trailing spaces
$line = trim(preg_replace("/[;#]\s.+$/", "", $line));
$line = trim(preg_replace("/\s+[;#]\s.+$/", "", $line));

if (empty($line) || $line[0] == ';' || $line[0] == '#') {
continue;
Expand Down
58 changes: 58 additions & 0 deletions test/classes/phing/system/util/PropertiesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/

require_once 'phing/system/util/Properties.php';

/**
* Unit test for Properties class
*
* @author Michiel Rook <[email protected]>
* @package phing.system.util
* @version $Id$
*/
class PropertiesTest extends PHPUnit_Framework_TestCase
{
/**
* @var Properties
*/
private $props = null;

public function setUp()
{
$this->props = new Properties();
}

public function tearDown()
{
unset($this->props);
}

public function testComments()
{
$file = new PhingFile(PHING_TEST_BASE . "/etc/system/util/comments.properties");
$this->props->load($file);

$this->assertEquals($this->props->getProperty('useragent'), 'Mozilla/5.0 (Windows NT 5.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1');
$this->assertEquals($this->props->getProperty('testline1'), 'Testline1');
$this->assertEquals($this->props->getProperty('testline2'), 'Testline2');
}
}
4 changes: 4 additions & 0 deletions test/etc/system/util/comments.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
useragent=Mozilla/5.0 (Windows NT 5.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1
testline1=Testline1 ; THIS IS A COMMENT
testline2=Testline2 # THIS IS A COMMENT

0 comments on commit 6163ba5

Please sign in to comment.