From: Tim Landscheidt Date: Thu, 29 Nov 2012 12:12:35 +0000 (+0000) Subject: (bug 40585) Don't drop 'step="any"' in HTML input fields. X-Git-Tag: 1.31.0-rc.0~21385^2 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=6dc4039270af99413cc7c3bf85b136d9a79e7497;p=lhc%2Fweb%2Fwiklou.git (bug 40585) Don't drop 'step="any"' in HTML input fields. The default value for "step" is "1" which effectively bans any decimal number from being entered into an 'type="number"' field and makes HTMLFloatField unusable. Change-Id: I103fd4047814a7fb0dfdc174f36badd5b660b7a4 --- diff --git a/includes/Html.php b/includes/Html.php index 2ab606912a..14456e4bee 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -476,7 +476,13 @@ class Html { // server-side validation. Opera is the only other implementation at // this time, and has ugly UI, so just kill the feature entirely until // we have at least one good implementation. - if ( in_array( $key, array( 'max', 'min', 'pattern', 'required', 'step' ) ) ) { + + // As the default value of "1" for "step" rejects decimal + // numbers to be entered in 'type="number"' fields, allow + // the special case 'step="any"'. + + if ( in_array( $key, array( 'max', 'min', 'pattern', 'required' ) ) || + $key === 'step' && $value !== 'any' ) { continue; } diff --git a/tests/phpunit/includes/HtmlTest.php b/tests/phpunit/includes/HtmlTest.php index 65dd9246de..47fa5f4605 100644 --- a/tests/phpunit/includes/HtmlTest.php +++ b/tests/phpunit/includes/HtmlTest.php @@ -605,4 +605,16 @@ class HtmlTest extends MediaWikiTestCase { return $ret; } + public function testFormValidationBlacklist() { + $this->assertEmpty( + Html::expandAttributes( array( 'min' => 1, 'max' => 100, 'pattern' => 'abc', 'required' => true, 'step' => 2 ) ), + 'Blacklist form validation attributes.' + ); + $this->assertEquals( + ' step=any', + Html::expandAttributes( array( 'min' => 1, 'max' => 100, 'pattern' => 'abc', 'required' => true, 'step' => 'any' ) ), + 'Allow special case "step=any".' + ); + } + }