PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » HTML_QuickForm » Bug #1576

xhtml compliant javascript should not use old comment hide hack

Details

Submitted2004-06-08 05:26 UTC
Fromricko at garagegames dot com
Assignedmansion
StatusClosed
PackageHTML_QuickForm
PHP VersionIrrelevant
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2004-06-08 05:26 UTC] ricko at garagegames dot com

Description:
------------
XHTML1.1 allows inline comments, scripts and styles, BUT they must be used with caution: if they use the <!-- ... --> comment notation within an element (such as to hide JavaScript from __very old__ browsers), XML parsers may or MAY NOT parse the text inside the comments (php's XML_parse skips the comments). Comments can be included as XML CDATA by using <![CDATA[ ... ]]>.

Propose an xhtml flag to toggle the inclusion of the <!-- --> comment notion, or just remove them.

Reproduce code:
---------------
Use client side validation.

Expected result:
----------------
<!-- --> comment tags removed

if (count($test) > 0) {
return
"\n<script type=\"text/javascript\">\n" .
"function validate_" . $this->_attributes['id'] . "(frm) {\n" .
" var value = '';\n" .
" var errFlag = new Array();\n" .
" _qfMsg = '';\n\n" .
join("\n", $test) .
"\n if (_qfMsg != '') {\n" .
" _qfMsg = '" . strtr($this->_jsPrefix, $js_escape) . "' + _qfMsg;\n" .
" _qfMsg = _qfMsg + '\\n" . strtr($this->_jsPostfix, $js_escape) . "';\n" .
" alert(_qfMsg);\n" .
" return false;\n" .
" }\n" .
" return true;\n" .
"}\n" .
"</script>";
}

Actual result:
--------------
if (count($test) > 0) {
return
"\n<script type=\"text/javascript\">\n" .
"<!-- \n" .
"function validate_" . $this->_attributes['id'] . "(frm) {\n" .
" var value = '';\n" .
" var errFlag = new Array();\n" .
" _qfMsg = '';\n\n" .
join("\n", $test) .
"\n if (_qfMsg != '') {\n" .
" _qfMsg = '" . strtr($this->_jsPrefix, $js_escape) . "' + _qfMsg;\n" .
" _qfMsg = _qfMsg + '\\n" . strtr($this->_jsPostfix, $js_escape) . "';\n" .
" alert(_qfMsg);\n" .
" return false;\n" .
" }\n" .
" return true;\n" .
"}\n" .
"//-->\n" .
"</script>";
}

[2004-06-08 05:37 UTC] ricko at garagegames dot com

Additional Information: http://wikibooks.org/wiki/XHTML_(XML)#Scripts_and_CSS_must_be_escaped

[2004-06-15 10:45 UTC] bmansion at mamasam dot com

I have fixed this by using //<![CDATA[ and //]]>
Using // makes it backward compatible as these are javascript comments.

Please report if this is ok for you before we release 3.2.3 this week. Thanks.

[2004-06-16 14:10 UTC] bmansion at mamasam dot com

What do you call "older browsers" ?

[2004-06-16 15:21 UTC] bmansion at mamasam dot com

I think that if you use // (javascript comments) in front of <![CDATA[ like I did, the line will be considered a comment by an older browser and so <![CDATA will be ignored. Don't you think ?

[2004-06-23 05:11 UTC] ricko at garagegames dot com

the //<![CDATA[ and //]]> fix works perfectly for me. All xhtml transitional browsers should be able to read this just fine.

[2004-06-28 15:09 UTC] bmansion at mamasam dot com

This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pear.php.net.

In case this was a pear.php.net website problem, the change will show
up on the website in short time.

Thank you for the report, and for helping us make PEAR better.