diff --git a/src/Definition/Code.php b/src/Definition/Code.php index a7b26e0..e0974e7 100644 --- a/src/Definition/Code.php +++ b/src/Definition/Code.php @@ -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) . '
';
}
}
diff --git a/src/Definition/Noparse.php b/src/Definition/Noparse.php
index 65c7eaf..351311a 100644
--- a/src/Definition/Noparse.php
+++ b/src/Definition/Noparse.php
@@ -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);
}
}
diff --git a/tests/integration/ParsingTest.php b/tests/integration/ParsingTest.php
index 4bac8df..214ac04 100644
--- a/tests/integration/ParsingTest.php
+++ b/tests/integration/ParsingTest.php
@@ -99,6 +99,12 @@ public function providerParseBBCode()
[],
'<h7>Header 7</h7>
',
],
+ // Do not double encode
+ [
+ '[code]<h7>Header 7</h7>[/code]',
+ [],
+ '<h7>Header 7</h7>
',
+ ],
[
'[code]
Durchmesser der Erde: D = 12742 km = 12742000 m
@@ -144,6 +150,12 @@ public function providerParseBBCode()
[],
'<h7>Header 7</h7>
', ], + // Do not double encode + [ + '[noparse]<h7>Header 7</h7>[/noparse]', + [], + '<h7>Header 7</h7>
', + ], // Urls [ 'example.org', diff --git a/tests/unit/Definition/CodeTest.php b/tests/unit/Definition/CodeTest.php index d32b0bc..455becd 100644 --- a/tests/unit/Definition/CodeTest.php +++ b/tests/unit/Definition/CodeTest.php @@ -34,6 +34,12 @@ public function dataProvider() null, '<span style="color:Red;">some text mit Umlauten äöü</span>
',
],
+ // Do not double encode
+ [
+ '<span style="color:Red;">some text mit Umlauten äöü</span>',
+ null,
+ '<span style="color:Red;">some text mit Umlauten äöü</span>
',
+ ],
[
'',
null,
diff --git a/tests/unit/Definition/NoparseTest.php b/tests/unit/Definition/NoparseTest.php
index 95d0738..09156f8 100644
--- a/tests/unit/Definition/NoparseTest.php
+++ b/tests/unit/Definition/NoparseTest.php
@@ -39,6 +39,12 @@ public function dataProvider()
null,
'',
],
+ // Do not double encode
+ [
+ '<h7>Header 7</h7>',
+ [],
+ '<h7>Header 7</h7>',
+ ],
];
}
}