From c654d4cd9e9419077719636784f6ef41e294c144 Mon Sep 17 00:00:00 2001 From: Jeroen De Dauw Date: Wed, 4 Jul 2018 03:45:43 +0200 Subject: [PATCH] Fix service parameter --- RELEASE-NOTES.md | 1 + src/ParameterExtractor.php | 2 +- tests/Integration/Parser/DisplayMapTest.php | 9 +++++++++ tests/Unit/ParameterExtractorTest.php | 10 ++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index ee76d33ac..d1c2bae39 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -7,6 +7,7 @@ different releases and which versions of PHP and MediaWiki they support, see the Released on July 4th, 2018. +* Fixed regression introduced in 5.5.0 causing the `#display_map` parameter `service` to often be ignored * Fixed fatal error when using `#display_map` parameter `circles` * Fixed fatal error when using `#display_map` parameter `rectangles` * Fixed `#display_map` parameter `rectangles` fill color modifier (it is no longer ignored) diff --git a/src/ParameterExtractor.php b/src/ParameterExtractor.php index 688cf974e..c9198b1d3 100644 --- a/src/ParameterExtractor.php +++ b/src/ParameterExtractor.php @@ -19,7 +19,7 @@ class ParameterExtractor { public function extract( array $parameterNames, array $rawParameters ) { foreach( $parameterNames as $parameterName ) { foreach ( $rawParameters as $rawName => $rawValue ) { - if ( strtolower( $rawName ) === $parameterName ) { + if ( trim( strtolower( $rawName ) ) === $parameterName ) { return trim( $rawValue ); } } diff --git a/tests/Integration/Parser/DisplayMapTest.php b/tests/Integration/Parser/DisplayMapTest.php index c2ba6e037..df0e1973b 100644 --- a/tests/Integration/Parser/DisplayMapTest.php +++ b/tests/Integration/Parser/DisplayMapTest.php @@ -135,4 +135,13 @@ public function testRectangleFillColorIsUsed() { ); } + public function testServiceSelectionWorksWhenItIsPrecededByMultipleParameters() { + $this->assertContains( + 'maps-googlemaps3', + $this->parse( + "{{#display_map:rectangles=\n 1,1:2,2~title~text~color\n| scrollwheelzoom=off\n| service = google}}" + ) + ); + } + } \ No newline at end of file diff --git a/tests/Unit/ParameterExtractorTest.php b/tests/Unit/ParameterExtractorTest.php index 970e2cb98..86344eb37 100644 --- a/tests/Unit/ParameterExtractorTest.php +++ b/tests/Unit/ParameterExtractorTest.php @@ -65,4 +65,14 @@ public function testWhenUpperCaseIsUsedInTheName_itIsStillFound() { ); } + public function testNameHasSpacesAroundIt_itIsStillFound() { + $this->assertSame( + 'value', + ( new ParameterExtractor() )->extract( + [ 'name' ], + [ ' name ' => 'value' ] + ) + ); + } + }