From 888bfddd335f6a22838a2c92afee14f09674b74c Mon Sep 17 00:00:00 2001 From: Philipp Kamps Date: Mon, 3 Oct 2016 14:37:52 +0200 Subject: [PATCH 1/4] commandURLCleanup now strips all unwanted chars at the end of the string --- lib/ezi18n/classes/ezchartransform.php | 4 +- .../tests/lib/ezi18n/ezchartransform_test.php | 41 +++++++++++++++++++ tests/tests/lib/ezi18n/suite.php | 22 ++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 tests/tests/lib/ezi18n/ezchartransform_test.php create mode 100644 tests/tests/lib/ezi18n/suite.php diff --git a/lib/ezi18n/classes/ezchartransform.php b/lib/ezi18n/classes/ezchartransform.php index c165beb4ef4..22d5bb3f199 100644 --- a/lib/ezi18n/classes/ezchartransform.php +++ b/lib/ezi18n/classes/ezchartransform.php @@ -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 unwanted chars from beginning/end array( $sep, - $sep, $sep, $sep, "" ), diff --git a/tests/tests/lib/ezi18n/ezchartransform_test.php b/tests/tests/lib/ezi18n/ezchartransform_test.php new file mode 100644 index 00000000000..4c7bbf374cc --- /dev/null +++ b/tests/tests/lib/ezi18n/ezchartransform_test.php @@ -0,0 +1,41 @@ +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' ); + } +} diff --git a/tests/tests/lib/ezi18n/suite.php b/tests/tests/lib/ezi18n/suite.php new file mode 100644 index 00000000000..a20574b24aa --- /dev/null +++ b/tests/tests/lib/ezi18n/suite.php @@ -0,0 +1,22 @@ +setName( "eZFile Test Suite" ); + $this->addTestSuite( 'eZCharTransFormTests' ); + } + + public static function suite() + { + return new self(); + } + +} From 0f37e08f5c53db35060e5059433e5b5bedd69c3b Mon Sep 17 00:00:00 2001 From: Philipp Kamps Date: Tue, 4 Oct 2016 13:48:39 +0200 Subject: [PATCH 2/4] Changing word TransForm to Transform, improving inline comment --- lib/ezi18n/classes/ezchartransform.php | 2 +- tests/tests/lib/ezi18n/ezchartransform_test.php | 6 +++--- tests/tests/lib/ezi18n/suite.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ezi18n/classes/ezchartransform.php b/lib/ezi18n/classes/ezchartransform.php index 22d5bb3f199..c0d3e53f441 100644 --- a/lib/ezi18n/classes/ezchartransform.php +++ b/lib/ezi18n/classes/ezchartransform.php @@ -397,7 +397,7 @@ static function commandUrlCleanup( $text, $charsetName ) $text = preg_replace( array( "#[^a-zA-Z0-9_!\.-]+#", "#\.\.+#", # Remove double dots "#[{$sepQ}]+#", # Turn multiple separators into one - "#^[{$sepQ}\.]+|[{$sepQ}!\.]+$#" ), # Strip unwanted chars from beginning/end + "#^[{$sepQ}\.]+|[{$sepQ}!\.]+$#" ), # Strip separator and dot from beginning, strip exclemation mark, dot and separator from end array( $sep, $sep, $sep, diff --git a/tests/tests/lib/ezi18n/ezchartransform_test.php b/tests/tests/lib/ezi18n/ezchartransform_test.php index 4c7bbf374cc..574178f87f8 100644 --- a/tests/tests/lib/ezi18n/ezchartransform_test.php +++ b/tests/tests/lib/ezi18n/ezchartransform_test.php @@ -1,17 +1,17 @@ setName( "eZCharTransFormTests" ); + $this->setName( "eZCharTransformTests" ); } public function setUp() diff --git a/tests/tests/lib/ezi18n/suite.php b/tests/tests/lib/ezi18n/suite.php index a20574b24aa..0e8a4f87c1c 100644 --- a/tests/tests/lib/ezi18n/suite.php +++ b/tests/tests/lib/ezi18n/suite.php @@ -11,7 +11,7 @@ public function __construct() { parent::__construct(); $this->setName( "eZFile Test Suite" ); - $this->addTestSuite( 'eZCharTransFormTests' ); + $this->addTestSuite( 'eZCharTransformTests' ); } public static function suite() From e76231651edd50bdce9cf339b1c3ea9286fa408b Mon Sep 17 00:00:00 2001 From: Philipp Kamps Date: Wed, 5 Oct 2016 09:29:24 +0200 Subject: [PATCH 3/4] Fixing typo --- lib/ezi18n/classes/ezchartransform.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ezi18n/classes/ezchartransform.php b/lib/ezi18n/classes/ezchartransform.php index c0d3e53f441..33f8e2b410f 100644 --- a/lib/ezi18n/classes/ezchartransform.php +++ b/lib/ezi18n/classes/ezchartransform.php @@ -397,7 +397,7 @@ static function commandUrlCleanup( $text, $charsetName ) $text = preg_replace( array( "#[^a-zA-Z0-9_!\.-]+#", "#\.\.+#", # Remove double dots "#[{$sepQ}]+#", # Turn multiple separators into one - "#^[{$sepQ}\.]+|[{$sepQ}!\.]+$#" ), # Strip separator and dot from beginning, strip exclemation mark, dot and separator from end + "#^[{$sepQ}\.]+|[{$sepQ}!\.]+$#" ), # Strip separator and dot from beginning, strip exclamation mark, dot and separator from end array( $sep, $sep, $sep, From 915c416b935294083ef462f4a21e3cda62253058 Mon Sep 17 00:00:00 2001 From: Philipp Kamps Date: Sun, 9 Oct 2016 05:10:52 -0400 Subject: [PATCH 4/4] Fix commandURLFixIRI as well - adding tests for it --- lib/ezi18n/classes/ezchartransform.php | 8 +++----- tests/tests/lib/ezi18n/ezchartransform_test.php | 11 +++++++++++ tests/tests/lib/ezi18n/suite.php | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/ezi18n/classes/ezchartransform.php b/lib/ezi18n/classes/ezchartransform.php index 33f8e2b410f..20250875bdd 100644 --- a/lib/ezi18n/classes/ezchartransform.php +++ b/lib/ezi18n/classes/ezchartransform.php @@ -410,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 @@ -420,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, "" ), diff --git a/tests/tests/lib/ezi18n/ezchartransform_test.php b/tests/tests/lib/ezi18n/ezchartransform_test.php index 574178f87f8..0338de71f45 100644 --- a/tests/tests/lib/ezi18n/ezchartransform_test.php +++ b/tests/tests/lib/ezi18n/ezchartransform_test.php @@ -38,4 +38,15 @@ public function testCommandUrlCleanupMultipleSpecialCharsAtEnd() $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 ); + } } diff --git a/tests/tests/lib/ezi18n/suite.php b/tests/tests/lib/ezi18n/suite.php index 0e8a4f87c1c..608ac47cb75 100644 --- a/tests/tests/lib/ezi18n/suite.php +++ b/tests/tests/lib/ezi18n/suite.php @@ -5,7 +5,7 @@ * @package tests */ -class eZFileTestSuite extends ezpTestSuite +class eZCharTransformTestSuite extends ezpTestSuite { public function __construct() {