Skip to content

Commit

Permalink
Nicht doppelt encoden
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Sep 6, 2016
1 parent e3e7d60 commit 631dcfb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Definition/Code.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ public function asHtml(ElementNode $el)
$content .= $child->getAsHTML();
}

return '<!-- no_p --><pre><code>' . htmlspecialchars($content) . '</code></pre><!-- no_p -->';
$flags = ENT_COMPAT | ENT_HTML401;
$encoding = ini_get("default_charset");
$double_encode = false; // Do not double encode

return '<!-- no_p --><pre><code>' . htmlspecialchars($content, $flags, $encoding, $double_encode) . '</code></pre><!-- no_p -->';
}

}
6 changes: 5 additions & 1 deletion src/Definition/Noparse.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ public function asHtml(ElementNode $el)
$content .= $child->getAsHTML();
}

return htmlspecialchars($content);
$flags = ENT_COMPAT | ENT_HTML401;
$encoding = ini_get("default_charset");
$double_encode = false; // Do not double encode

return htmlspecialchars($content, $flags, $encoding, $double_encode);
}

}
12 changes: 12 additions & 0 deletions tests/integration/ParsingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ public function providerParseBBCode()
[],
'<pre><code>&lt;h7&gt;Header 7&lt;/h7&gt;</code></pre>',
],
// Do not double encode
[
'[code]&lt;h7&gt;Header 7&lt;/h7&gt;[/code]',
[],
'<pre><code>&lt;h7&gt;Header 7&lt;/h7&gt;</code></pre>',
],
[
'[code]
Durchmesser der Erde: D = 12742 km = 12742000 m
Expand Down Expand Up @@ -144,6 +150,12 @@ public function providerParseBBCode()
[],
'<p>&lt;h7&gt;Header 7&lt;/h7&gt;</p>',
],
// Do not double encode
[
'[noparse]&lt;h7&gt;Header 7&lt;/h7&gt;[/noparse]',
[],
'<p>&lt;h7&gt;Header 7&lt;/h7&gt;</p>',
],
// Urls
[
'example.org',
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/Definition/CodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public function dataProvider()
null,
'<!-- no_p --><pre><code>&lt;span style=&quot;color:Red;&quot;&gt;some text mit Umlauten äöü&lt;/span&gt;</code></pre><!-- no_p -->',
],
// Do not double encode
[
'&lt;span style=&quot;color:Red;&quot;&gt;some text mit Umlauten äöü&lt;/span&gt;',
null,
'<!-- no_p --><pre><code>&lt;span style=&quot;color:Red;&quot;&gt;some text mit Umlauten äöü&lt;/span&gt;</code></pre><!-- no_p -->',
],
[
'',
null,
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/Definition/NoparseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public function dataProvider()
null,
'',
],
// Do not double encode
[
'&lt;h7&gt;Header 7&lt;/h7&gt;',
[],
'&lt;h7&gt;Header 7&lt;/h7&gt;',
],
];
}
}

0 comments on commit 631dcfb

Please sign in to comment.