Html: Throw exception if array is used for an attribute not supporting it
authorThiemo Mättig <thiemo.maettig@wikimedia.de>
Sat, 10 May 2014 08:58:19 +0000 (10:58 +0200)
committerKrinkle <krinklemail@gmail.com>
Thu, 10 Jul 2014 16:46:35 +0000 (16:46 +0000)
commit4aeb08ef1885a89009f44de4229ccbd63c7e4f1c
tree20b0efe4a2371d59b2642f4b94df28273b0342e7
parent16eb4480e815a754dfb8c9320778f40c5b2cc016
Html: Throw exception if array is used for an attribute not supporting it

Previously the behavior was more or less undefined for most attributes
except for the ones in $spaceSeparatedListAttributes (currently 'class',
'accesskey' and 'rel'). If an other attribute is set to an array (no
matter what it contains) the method produces broken HTML like
'key=' and only triggers a warning if error_reporting is enabled. If
error_reporting is not enabled a developer may overlook this.

To clarify: The method always *ALLOWS* array values. This is *NOT*
about unexpected types in the call signature but unexpected
combinations of nested values. These combinations are already
checked in the method but the check was incomplete.

I considered several solutions:
* Simply use the first array element. But we can't know if the first
  element is what the caller expected.
* Silently drop all arrays if the attribute doesn't allow lists. This
  is close to the current behavior of always returning 'key=' but is a
  breaking change for boolean attributes like 'checked' and 'selected'.
  Browsers accept the current 'checked=' as true while omiting the
  attribute means false.

Choosing to always throw an exception. As above, this is a
breaking change in some cases.

Change-Id: Id5fcbdef2696d0a81a91d54338939ee678475ca3
includes/Html.php
tests/phpunit/includes/HtmlTest.php