Skip to content

Commit

Permalink
Fixes #4 - html encode injected properties and enable test
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw authored and CiviCRM committed Sep 16, 2020
1 parent 65c9e7a commit 8e35b9e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ext/afform/core/afform.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ function afform_civicrm_alterAngular($angular) {
continue;
}
foreach ($field as &$prop) {
$prop = json_encode($prop, JSON_UNESCAPED_SLASHES);
$prop = htmlspecialchars(CRM_Utils_JS::encode($prop));
}
if ($existingFieldDefn) {
$field = array_merge($field, CRM_Utils_JS::getRawProps($existingFieldDefn));
Expand Down
23 changes: 12 additions & 11 deletions ext/afform/core/tests/phpunit/Civi/Afform/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ public function testDefnInjectionNested() {
$this->assertEquals('First Name', $myField['defn']['title']);
}

//public function testDefnOverrideTitle() {
// $inputHtml = sprintf(self::PERSON_TPL,
// '<div af-fieldset="person"><af-field name="first_name" defn="{title: \'Given name\'}" /></div>');
// $filteredHtml = _afform_html_filter('~afform/MyForm.html', $inputHtml);
// $converter = new \CRM_Afform_ArrayHtml(TRUE);
// $parsed = $converter->convertHtmlToArray($filteredHtml);
//
// $myField = $parsed[0]['#children'][1]['#children'][0];
// $this->assertEquals('af-field', $myField['#tag']);
// $this->assertEquals('Given name', $myField['defn']['title']);
//}
public function testDefnOverrideTitle() {
$inputHtml = sprintf(self::PERSON_TPL,
'<div af-fieldset="person"><af-field name="first_name" defn="{title: \'Given name\'}" /></div>');
$filteredHtml = _afform_html_filter('~afform/MyForm.html', $inputHtml);
$converter = new \CRM_Afform_ArrayHtml(TRUE);
$parsed = $converter->convertHtmlToArray($filteredHtml);

$myField = $parsed[0]['#children'][1]['#children'][0];
$this->assertEquals('af-field', $myField['#tag']);
$this->assertEquals('Given name', $myField['defn']['title']);
$this->assertEquals('Text', $myField['defn']['input_type']);
}

}

0 comments on commit 8e35b9e

Please sign in to comment.