Skip to content

Commit

Permalink
Escaping attributes and adding unit test (see #49)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregwar committed Mar 26, 2019
1 parent 936a19d commit 3025618
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public function getHtml()
$html = '<input ';

foreach ($this->attributes as $name => $value) {
$html.= $name.'="'.$value.'" ';
$html.= $name.'="'.htmlspecialchars($value).'" ';
}

if ($this->required) {
Expand Down
18 changes: 18 additions & 0 deletions tests/FormTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,24 @@ public function testAccessingNotExistingField()
$form->getField('titi');
}

public function testQuotesAttributes()
{
$form = $this->getForm('quotes.html');
$field = $form->getField('xxx');

$this->assertTrue($field->hasAttribute('foo'));
$this->assertEquals($field->getAttribute('foo'), 'bar baz "bax"');

$doc = new DOMDocument();
$doc->loadHTML("$form");
$element = $doc->getElementById('theinput');

$this->assertFalse($element == null);
$this->assertTrue($element->hasAttribute('foo'));
$this->assertEquals($element->getAttribute('foo'), 'bar baz "bax"');

}

public function testPlaceholder()
{
$form = $this->getForm('placeholder.html');
Expand Down
3 changes: 3 additions & 0 deletions tests/files/form/quotes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<form method="post">
<input id="theinput" type="text" name="xxx" foo='bar baz "bax"' />
</form>

0 comments on commit 3025618

Please sign in to comment.