-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(output): fewer view $vars will be output by accident
A general problem is views passing along arbitrary $vars values to views like output/url, which treat unrecognized $vars as HTML attributes. This at least strips keys with underscores, which are definitely not meant to be HTML attributes. Fixes Elgg#8218
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
engine/tests/phpunit/Elgg/lib/output/FormatAttributesTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
namespace Elgg\lib\output; | ||
|
||
class FormatAttributesTest extends \PHPUnit_Framework_TestCase { | ||
|
||
public function testGeneralUsage() { | ||
$attrs = [ | ||
'A' => 'Hello & & < <', | ||
'b' => false, // ignored | ||
'c' => true, | ||
'd' => null, // ignored | ||
'e' => ['&', '&', '<', '<'], | ||
'f' => (object)['foo' => 'bar'], // ignored | ||
]; | ||
$expected = 'a="Hello & & < <" c="c" e="& & < <"'; | ||
|
||
$this->assertEquals($expected, elgg_format_attributes($attrs)); | ||
} | ||
|
||
public function testFiltersUnderscoreKeysExceptDataAttributes() { | ||
$attrs = [ | ||
'foo_bar' => 'a', | ||
'data-foo_bar' => 'b', | ||
]; | ||
$expected = 'data-foo_bar="b"'; | ||
|
||
$this->assertEquals($expected, elgg_format_attributes($attrs)); | ||
} | ||
|
||
public function testLowercasesAllAttributes() { | ||
$attrs = [ | ||
'A-B' => true, | ||
'C-D' => 'C-D', | ||
]; | ||
$expected = 'a-b="a-b" c-d="C-D"'; | ||
|
||
$this->assertEquals($expected, elgg_format_attributes($attrs)); | ||
} | ||
} |