Bug #71452 [Opn->Nab]: Error parsing js strings which include tags.
Edit report at https://bugs.php.net/bug.php?id=71452&edit=1
ID: 71452
Updated by: requinix@php.net
Reported by: php at carl-ambroselli dot de
Summary: Error parsing js strings which include tags.
-Status: Open
+Status: Not a bug
Type: Bug
Package: DOM XML related
Operating System: Tested MacOS & Debian
PHP Version: 5.5.31
Block user comment: N
Private report: N
New Comment:
This is an issue with libxml, not PHP.
HTML 4 prohibits the use of "</" in non-HTML data, meaning the "</p>"
will be interpreted as an end tag. However the "<p>" before will be totally ignored.
libxml recovers from the <script></p> mismatch by dropping the unexpected end tag - with
a warning.
HTML 5 has slightly different rules which allow for "</p>", but libxml does not
currently support HTML 5.
Best practice is still to escape fake end tags in <script>s. That applies in PHP too.
var p = '<p>123<\/p>'
Previous Comments:
------------------------------------------------------------------------
[2017-07-05 06:48:08] qdinar at gmail dot com
i have reported another bug https://bugs.php.net/bug.php?id=74858 because i
have found that it differs from this by additional CDATA tag.
------------------------------------------------------------------------
[2017-07-05 06:35:43] qdinar at gmail dot com
i confirm this for php 5.6.30 in windows 10.
------------------------------------------------------------------------
[2016-01-26 10:38:06] php at carl-ambroselli dot de
Description:
------------
DomDocument fails to parse a document if it includes JavaScript Strings with HTML Tags inside the
strings.
Test script:
---------------
$doc = new DomDocument();
$doc->loadHTML('<html><body><script>var p =
\'<p>123</p>\'</script></body></html>');
echo $doc->saveHTML();
Expected result:
----------------
<html><body><script>var p =
\'<p>123</p>\'</script></body></html>
Actual result:
--------------
<html><body><script>var p =
'<p>123'</script></body></html>
(The closing </p> tag got removed inside a JavaScript string)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71452&edit=1
Thread (4 messages)