jenkins-bot has submitted this change and it was merged.

Change subject: Fix and test double escaping in GlobeCoordinateDetailsFormatter
......................................................................


Fix and test double escaping in GlobeCoordinateDetailsFormatter

I'm using a quite complex mock object to allow testing for values that
are not supported by the data value object itself.

Change-Id: Ieebe052c491ad1737867e263f6d16c3a48d87113
---
M lib/includes/formatters/GlobeCoordinateDetailsFormatter.php
M lib/tests/phpunit/formatters/GlobeCoordinateDetailsFormatterTest.php
2 files changed, 34 insertions(+), 3 deletions(-)

Approvals:
  Hoo man: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/includes/formatters/GlobeCoordinateDetailsFormatter.php 
b/lib/includes/formatters/GlobeCoordinateDetailsFormatter.php
index b88cb30..8a34e07 100644
--- a/lib/includes/formatters/GlobeCoordinateDetailsFormatter.php
+++ b/lib/includes/formatters/GlobeCoordinateDetailsFormatter.php
@@ -81,7 +81,7 @@
 
        /**
         * @param string $fieldName
-        * @param string $valueHtml
+        * @param string $valueHtml HTML
         *
         * @return string HTML for the label/value pair
         */
@@ -90,7 +90,7 @@
 
                $html .= Html::element( 'th', array( 'class' => 'wb-globe-' . 
$fieldName ),
                        $this->getFieldLabel( $fieldName )->text() );
-               $html .= Html::element( 'td', array( 'class' => 'wb-globe-' . 
$fieldName ),
+               $html .= Html::rawElement( 'td', array( 'class' => 'wb-globe-' 
. $fieldName ),
                        $valueHtml );
 
                $html .= Html::closeElement( 'tr' );
diff --git 
a/lib/tests/phpunit/formatters/GlobeCoordinateDetailsFormatterTest.php 
b/lib/tests/phpunit/formatters/GlobeCoordinateDetailsFormatterTest.php
index ae908c5..e9c8b39 100644
--- a/lib/tests/phpunit/formatters/GlobeCoordinateDetailsFormatterTest.php
+++ b/lib/tests/phpunit/formatters/GlobeCoordinateDetailsFormatterTest.php
@@ -54,11 +54,42 @@
        }
 
        public function testFormatError() {
-               $formatter = new GlobeCoordinateDetailsFormatter( new 
FormatterOptions() );
+               $formatter = new GlobeCoordinateDetailsFormatter();
                $value = new NumberValue( 23 );
 
                $this->setExpectedException( 'InvalidArgumentException' );
                $formatter->format( $value );
        }
 
+       public function testEscaping() {
+               $value = $this->getMock(
+                       'DataValues\Geo\Values\GlobeCoordinateValue',
+                       array( 'getLatitude', 'getLongitude', 'getPrecision' ),
+                       array( new LatLongValue( 0, 0 ), null, '<GLOBE>' )
+               );
+               $value->expects( $this->any() )
+                       ->method( 'getLatitude' )
+                       ->will( $this->returnValue( '<LAT>' ) );
+               $value->expects( $this->any() )
+                       ->method( 'getLongitude' )
+                       ->will( $this->returnValue( '<LONG>' ) );
+               $value->expects( $this->any() )
+                       ->method( 'getPrecision' )
+                       ->will( $this->returnValue( '<PRECISION>' ) );
+
+               $formatter = new GlobeCoordinateDetailsFormatter();
+               $formatted = $formatter->format( $value );
+
+               $this->assertContains( '&lt;LAT&gt;', $formatted );
+               $this->assertContains( '&lt;LONG&gt;', $formatted );
+               $this->assertContains( '&lt;PRECISION&gt;', $formatted );
+               $this->assertContains( '&lt;GLOBE&gt;', $formatted );
+
+               $this->assertNotContains( '<LAT>', $formatted, 'never 
unescaped' );
+               $this->assertNotContains( '<LONG>', $formatted, 'never 
unescaped' );
+               $this->assertNotContains( '<PRECISION>', $formatted, 'never 
unescaped' );
+               $this->assertNotContains( '<GLOBE>', $formatted, 'never 
unescaped' );
+               $this->assertNotContains( '&amp;', $formatted, 'no double 
escaping' );
+       }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/265243
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ieebe052c491ad1737867e263f6d16c3a48d87113
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Adrian Lang <[email protected]>
Gerrit-Reviewer: Bene <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to