Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/265243
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(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/43/265243/1
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( '<LAT>', $formatted );
+ $this->assertContains( '<LONG>', $formatted );
+ $this->assertContains( '<PRECISION>', $formatted );
+ $this->assertContains( '<GLOBE>', $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( '&', $formatted, 'no double
escaping' );
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/265243
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieebe052c491ad1737867e263f6d16c3a48d87113
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits