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 all 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
12 changes: 4 additions & 8 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 exclamation mark, dot and separator from end
array( $sep,
$sep,
$sep,
$sep,
"" ),
Expand All @@ -412,7 +410,7 @@ static function commandUrlCleanupIRI( $text, $charsetName )
{
// With IRI support we keep all characters except some reserved ones,
// they are space, tab, ampersand, semi-colon, forward slash, colon, equal sign, question mark,
// square brackets, parenthesis, plus.
// square brackets, parenthesis, plus, double quote.
//
// Note: Spaces and tabs are turned into a dash to make it easier for people to
// paste urls from the system and have the whole url recognized
Expand All @@ -422,13 +420,11 @@ static function commandUrlCleanupIRI( $text, $charsetName )
$prepost = " ." . $sepQ;
if ( $sep != "-" )
$prepost .= "-";
$text = preg_replace( array( "#[ \t\\\\%\#&;/:=?\[\]()+]+#",
"#^[\.]+|[!\.]+$#", # Remove dots at beginning/end
$text = preg_replace( array( "#[ \t\\\\%\#&;/:=?\[\]()+\"]+#",
"#\.\.+#", # Remove double dots
"#[{$sepQ}]+#", # Turn multiple separators into one
"#^[{$prepost}]+|[{$prepost}]+$#" ),
"#^[{$prepost}]+|[!{$prepost}]+$#" ), # Strip "!", dots and separator from beginning/end
array( $sep,
$sep,
$sep,
$sep,
"" ),
Expand Down
52 changes: 52 additions & 0 deletions tests/tests/lib/ezi18n/ezchartransform_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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' );
}

public function testCommandUrlCleanupIRI()
{
$objectName = '.täst."';
$transformed = eZCharTransform::commandUrlCleanupIRI( $objectName );
$this->assertEquals( 'täst', $transformed );

$objectName = '.test!"';
$transformed = eZCharTransform::commandUrlCleanupIRI( $objectName );
$this->assertEquals( 'test', $transformed );
}
}
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 eZCharTransformTestSuite extends ezpTestSuite
{
public function __construct()
{
parent::__construct();
$this->setName( "eZFile Test Suite" );
$this->addTestSuite( 'eZCharTransformTests' );
}

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

}