Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commandURLCleanup now strips all unwanted chars at the end of the string #17

Merged
merged 4 commits into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/ezi18n/classes/ezchartransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,10 @@ static function commandUrlCleanup( $text, $charsetName )
$sep = eZCharTransform::wordSeparator();
$sepQ = preg_quote( $sep );
$text = preg_replace( array( "#[^a-zA-Z0-9_!\.-]+#",
"#^[\.]+|[!\.]+$#", # Remove dots at beginning/end
"#\.\.+#", # Remove double dots
"#[{$sepQ}]+#", # Turn multiple separators into one
"#^[{$sepQ}]+|[{$sepQ}]+$#" ), # Strip separator from beginning/end
"#^[{$sepQ}\.]+|[{$sepQ}!\.]+$#" ), # Strip separator and dot from beginning, strip exclemation mark, dot and separator from end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: should be "exclamation"

array( $sep,
$sep,
$sep,
$sep,
"" ),
Expand Down
41 changes: 41 additions & 0 deletions tests/tests/lib/ezi18n/ezchartransform_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* File containing the eZCharTransformTests class
*
* @package tests
*/

class eZCharTransformTests extends ezpTestCase
{

public function __construct()
{
parent::__construct();
$this->setName( "eZCharTransformTests" );
}

public function setUp()
{
parent::setUp();
}

public function tearDown()
{
parent::tearDown();
}

public function testCommandUrlCleanupMultipleSpecialCharsAtEnd()
{
$objectName = 'test."';
$transformed = eZCharTransform::commandUrlCleanup( $objectName );
$this->assertEquals( $transformed, 'test' );

$objectName = 'te.st."';
$transformed = eZCharTransform::commandUrlCleanup( $objectName );
$this->assertEquals( $transformed, 'te.st' );

$objectName = '.test!"';
$transformed = eZCharTransform::commandUrlCleanup( $objectName );
$this->assertEquals( $transformed, 'test' );
}
}
22 changes: 22 additions & 0 deletions tests/tests/lib/ezi18n/suite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* File containing the eZFileTestSuite class
*
* @package tests
*/

class eZFileTestSuite extends ezpTestSuite
{
public function __construct()
{
parent::__construct();
$this->setName( "eZFile Test Suite" );
$this->addTestSuite( 'eZCharTransformTests' );
}

public static function suite()
{
return new self();
}

}