Skip to content
Snippets Groups Projects
Unverified Commit 389e1856 authored by Michael Große's avatar Michael Große
Browse files

fix: prevent two selected options, b/c apparently 'String' == 0 :face_palm:

There was a bug, where the options array ['Auto', 0, 1] would result in
HTML option tags where both the 'Auto' and the 0 option were selected.
parent 07ca0ccf
No related branches found
No related tags found
No related merge requests found
......@@ -129,6 +129,21 @@ class form_dropdownelement_test extends DokuWikiTest {
$this->assertEquals('label of third option', $selected->text());
}
/**
* Prevent double select that might occur because `'Auto' == 0` is true
*/
public function test_doubleselect() {
$form = new Form\Form();
$form->addDropdown('foo', ['Auto', 0, 1]);
$html = $form->toHTML();
$pq = phpQuery::newDocumentXHTML($html);
$selected = $pq->find('option[selected=selected]');
$this->assertEquals(1, $selected->length);
$this->assertEquals('Auto', $selected->text());
}
/**
* Ensure that there is always only a single one selected option
*/
......
......@@ -88,7 +88,7 @@ class OptGroup extends Element {
protected function renderOptions() {
$html = '';
foreach($this->options as $key => $val) {
$selected = ($key == $this->value) ? ' selected="selected"' : '';
$selected = ((string)$key === (string)$this->value) ? ' selected="selected"' : '';
$attrs = '';
if (!empty($val['attrs']) && is_array($val['attrs'])) {
$attrs = buildAttributes($val['attrs']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment