Aude has uploaded a new change for review. https://gerrit.wikimedia.org/r/250030
Change subject: Trim whitespace from input in Special:SetLabelDescriptionAliases ...................................................................... Trim whitespace from input in Special:SetLabelDescriptionAliases Bug: T117184 Change-Id: I29eb388390a720c67529222ac9c3929a2d9a24ef --- M repo/includes/specials/SpecialSetLabelDescriptionAliases.php M repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php 2 files changed, 30 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/30/250030/1 diff --git a/repo/includes/specials/SpecialSetLabelDescriptionAliases.php b/repo/includes/specials/SpecialSetLabelDescriptionAliases.php index b14d475..57d6982 100644 --- a/repo/includes/specials/SpecialSetLabelDescriptionAliases.php +++ b/repo/includes/specials/SpecialSetLabelDescriptionAliases.php @@ -248,14 +248,7 @@ * @param string $subPage */ protected function prepareArguments( $subPage ) { - $request = $this->getRequest(); - $parts = $subPage === '' ? array() : explode( '/', $subPage, 2 ); - - $this->languageCode = $request->getVal( 'language', isset( $parts[1] ) ? $parts[1] : '' ); - $this->label = $request->getVal( 'label', '' ); - $this->description = $request->getVal( 'description', '' ); - $aliasesText = $request->getVal( 'aliases', '' ); - $this->aliases = $aliasesText === '' ? array() : explode( '|', $aliasesText ); + $this->extractInput( $subPage ); // Parse the 'id' parameter and throw an exception if the entity cannot be loaded parent::prepareArguments( $subPage ); @@ -277,6 +270,33 @@ } } + /** + * @param string $subPage + */ + private function extractInput( $subPage ) { + $request = $this->getRequest(); + $parts = $subPage === '' ? array() : explode( '/', $subPage, 2 ); + + $this->languageCode = $request->getVal( 'language', isset( $parts[1] ) ? $parts[1] : '' ); + $this->label = $this->stringNormalizer->trimToNFC( + $request->getVal( 'label', '' ) + ); + $this->description = $this->stringNormalizer->trimToNFC( + $request->getVal( 'description', '' ) + ); + + $aliasesText = $request->getVal( 'aliases', '' ); + $aliases = $aliasesText === '' ? array() : explode( '|', $aliasesText ); + + $self = $this; + + $this->aliases = array_map( function( $alias ) use( $self ) { + return $self->stringNormalizer->trimToNFC( $alias ); + }, + $aliases + ); + } + private function setFingerprintFields( Fingerprint $fingerprint ) { if ( !$this->getRequest()->getCheck( 'label' ) && $fingerprint->hasLabel( $this->languageCode ) diff --git a/repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php b/repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php index e37fd76..e932a23 100644 --- a/repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php +++ b/repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php @@ -304,7 +304,7 @@ 'add label' => array( $fooFingerprint, '$id', - new FauxRequest( array( 'language' => 'en', 'label' => 'FOO' ), true ), + new FauxRequest( array( 'language' => 'en', 'label' => 'FOO ' ), true ), array(), $this->makeFingerprint( array( 'de' => 'foo', 'en' => 'FOO' ) @@ -335,7 +335,7 @@ 'set aliases' => array( $fooFingerprint, '$id', - new FauxRequest( array( 'language' => 'de', 'aliases' => 'foo|bar' ), true ), + new FauxRequest( array( 'language' => 'de', 'aliases' => 'foo |bar' ), true ), array(), $this->makeFingerprint( array( 'de' => 'foo' ), -- To view, visit https://gerrit.wikimedia.org/r/250030 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I29eb388390a720c67529222ac9c3929a2d9a24ef Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aude <aude.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits