Skip to content

Commit

Permalink
avoid double escaped entities in labels
Browse files Browse the repository at this point in the history
  • Loading branch information
becoded authored and neilime committed Jun 2, 2023
1 parent 6b48ff6 commit 3e484c9
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/TwbsHelper/Form/View/Helper/FormLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public function __invoke(
return $labelContent;
}



$labelAttributes = $this->prepareLabelAttributes($element);
$markup = parent::__invoke($element, $labelContent, $position);

Expand Down Expand Up @@ -71,7 +69,7 @@ public function __invoke(
'div',
$labelAttributes,
$label,
!$element->getLabelOption('disable_html_escape')
false
);
}

Expand Down
212 changes: 212 additions & 0 deletions tests/TestSuite/TwbsHelper/Form/View/Helper/FormLabelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
<?php

namespace TestSuite\TwbsHelper\Form\View\Helper;

class FormLabelTest extends \TestSuite\TwbsHelper\AbstractViewHelperTestCase
{
/**
* @var \TwbsHelper\Form\View\Helper\FormLabel
*/
protected $helper = 'formLabel';

/**
* @dataProvider dataProviderRenderLabels
*/
public function testRenderWithLabel($element, string $expected)
{
$this->assertEquals(
$expected,
$this->helper->__invoke($element)
);
}

public function dataProviderRenderLabels(): array
{
return [
[
new \Laminas\Form\Element\Text(
'test_one',
[
'label' => 'Without special chars',
]
),
'<label class="form-label" for="test_one">Without special chars</label>'
],
[
new \Laminas\Form\Element\Text(
'test_one',
[
'label' => 'With special chars < > &',
]
),
'<label class="form-label" for="test_one">With special chars &lt; &gt; &amp;</label>'
],
[
new \Laminas\Form\Element\Text(
'test_one',
[
'label' => 'With special chars &lt; &gt; &amp;',
]
),
'<label class="form-label" for="test_one">With special chars &amp;lt; &amp;gt; &amp;amp;</label>'
],
[
new \Laminas\Form\Element\Text(
'test_one',
[
'label' => 'With a quote\'',
]
),
'<label class="form-label" for="test_one">With a quote&#039;</label>'
],
[
new \Laminas\Form\Element\MultiCheckbox(
'test_one',
[
'label' => 'Without special chars',
]
),
'<div class="form-label">
Without special chars
</div>'
],
[
new \Laminas\Form\Element\MultiCheckbox(
'test_one',
[
'label' => 'With special chars < > &',
]
),
'<div class="form-label">
With special chars &lt; &gt; &amp;
</div>'
],
[
new \Laminas\Form\Element\MultiCheckbox(
'test_one',
[
'label' => 'With special chars &lt; &gt; &amp;',
]
),
'<div class="form-label">
With special chars &amp;lt; &amp;gt; &amp;amp;
</div>'
],
[
new \Laminas\Form\Element\MultiCheckbox(
'test_one',
[
'label' => 'With a quote\'',
]
),
'<div class="form-label">
With a quote&#039;
</div>'
],
[
new \Laminas\Form\Element\Text(
'test_one',
[
'label' => 'Without special chars',
'label_options' => [
'disable_html_escape' => true,
],
]
),
'<label class="form-label" for="test_one">Without special chars</label>'
],
[
new \Laminas\Form\Element\Text(
'test_one',
[
'label' => 'With special chars < > &',
'label_options' => [
'disable_html_escape' => true,
],
]
),
'<label class="form-label" for="test_one">With special chars < > &</label>'
],
[
new \Laminas\Form\Element\Text(
'test_one',
[
'label' => 'With special chars &lt; &gt; &amp;',
'label_options' => [
'disable_html_escape' => true,
],
]
),
'<label class="form-label" for="test_one">With special chars &lt; &gt; &amp;</label>'
],
[
new \Laminas\Form\Element\Text(
'test_one',
[
'label' => 'With a quote\'',
'label_options' => [
'disable_html_escape' => true,
],
]
),
'<label class="form-label" for="test_one">With a quote\'</label>'
],
[
new \Laminas\Form\Element\MultiCheckbox(
'test_one',
[
'label' => 'Without special chars',
'label_options' => [
'disable_html_escape' => true,
],
]
),
'<div class="form-label">
Without special chars
</div>'
],
[
new \Laminas\Form\Element\MultiCheckbox(
'test_one',
[
'label' => 'With special chars < > &',
'label_options' => [
'disable_html_escape' => true,
],
]
),
'<div class="form-label">
With special chars < > &
</div>'
],
[
new \Laminas\Form\Element\MultiCheckbox(
'test_one',
[
'label' => 'With special chars &lt; &gt; &amp;',
'label_options' => [
'disable_html_escape' => true,
],
]
),
'<div class="form-label">
With special chars &lt; &gt; &amp;
</div>'
],
[
new \Laminas\Form\Element\MultiCheckbox(
'test_one',
[
'label' => 'With a quote\'',
'label_options' => [
'disable_html_escape' => true,
],
]
),
'<div class="form-label">
With a quote\'
</div>'
],
];
}
}

0 comments on commit 3e484c9

Please sign in to comment.