Skip to content

Commit

Permalink
Skip sometimes attribute escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
goetas committed Jul 31, 2014
1 parent 24e497a commit bd57514
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ private function esapeUrls(\DOMDocument $doc, \DOMXPath $xp)
$res = $this->xpathQuery($xp, "(//xh:*/@href|//xh:*/@src)[contains(., '{$this->options['tag_variable'][0]}') and contains(., '{$this->options['tag_variable'][1]}')]", $doc, false);
foreach ($res as $node) {

// href="{{ foo }}://{{ bar }}" or similar, are skipped
if (preg_match('{^' . preg_quote($this->options['tag_variable'][0]) . '((' . self::REGEX_STRING . '|[^"\']*)+)' . preg_quote($this->options['tag_variable'][1]) . '$}siuU', str_replace($this->placeholder, '', $node->value))) {
// if the twig variable is at the beginning of attribute, we should skip it
if (preg_match('{^' . preg_quote($this->options['tag_variable'][0]) . '((' . self::REGEX_STRING . '|[^"\']*)+)' . preg_quote($this->options['tag_variable'][1]) . '}siuU', str_replace($this->placeholder, '', $node->value))) {
continue;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/Goetas/Twital/Tests/ContextAwareEscapingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ public function getData()
'<a href="foo?q={{ ( foo ) | escape(\'url\') }}">bar</a>',
),

array(
'<a href="{{ foo }}?foo=bar">bar</a>',
'<a href="{{ foo }}?foo=bar">bar</a>',
),

array(
'<img src="a.gif?a=b&amp;{{ foo }}"/>',
'<img src="a.gif?a=b&amp;{{ ( foo ) | escape(\'url\') }}"/>'
Expand Down

0 comments on commit bd57514

Please sign in to comment.