You are here: Foswiki>Tasks Web>Item12419 (29 May 2014, GeorgeClark)Edit Attach

Item12419: JQueryPlugin emits the code which is not HTML compatible (does not pass validator.w3.org)

pencil
Priority: Normal
Current State: Duplicate
Released In: n/a
Target Release: n/a
Applies To: Extension
Component:
Branches:
Reported By: PiotrRoszatycki
Waiting For:
Last Change By: GeorgeClark
Output from validator.w3.org:

Validation Output: 2 Errors

 Line 123, Column 36: character "&" is the first character of a delimiter but occurred as data
    "NAMEFILTER": "[\s\*?~^\$@%`\"'&;|<>\[\]#\x00-\x1f]"
✉
This message may appear in several cases:

You tried to include the "<" character in your page: you should escape it as "<"
You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&", which is always safe.
Another possibility is that you forgot to close quotes in a previous tag.
 Line 123, Column 39: character "<" is the first character of a delimiter but occurred as data
    "NAMEFILTER": "[\s\*?~^\$@%`\"'&;|<>\[\]#\x00-\x1f]"
✉
This message may appear in several cases:

You tried to include the "<" character in your page: you should escape it as "<"
You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&", which is always safe.
Another possibility is that you forgot to close quotes in a previous tag.
 Line 123, Column 36: xmlParseEntityRef: no name
    "NAMEFILTER": "[\s\*?~^\$@%`\"'&;|<>\[\]#\x00-\x1f]"
✉
 Line 123, Column 39: StartTag: invalid element name
    "NAMEFILTER": "[\s\*?~^\$@%`\"'&;|<>\[\]#\x00-\x1f]"

The solution is to enclose JavaScript code in CDATA sesion or SGML comment.

Patch from https://github.com/foswiki/JQueryPlugin/pull/2

commit 9f1e51ad06a842168cba3cd9a66f2075c00aa763
Author: Piotr Roszatycki <piotr.roszatycki@gmail.com>
Date:   Sun Mar 10 13:02:52 2013 +0100

    Use SGML CDATA section for generated JavaScript code to make validator.w3.org happy

diff --git a/lib/Foswiki/Plugins/JQueryPlugin/FOSWIKI.pm b/lib/Foswiki/Plugins/JQueryPlugin/FOSWIKI.pm
index 85bb438..bef318a 100644
--- a/lib/Foswiki/Plugins/JQueryPlugin/FOSWIKI.pm
+++ b/lib/Foswiki/Plugins/JQueryPlugin/FOSWIKI.pm
@@ -83,9 +83,9 @@ sub init {
           '    "' . $pref . '": "%ENCODE{"%' . $pref . '%" type="quote"}%"';
     }
     my $text =
-"<script type='text/javascript'>\njQuery.extend(foswiki, {\n \"preferences\": {\n"
+"<script type='text/javascript'>\n<![CDATA[\njQuery.extend(foswiki, {\n \"preferences\": {\n"
       . join( ",\n", @prefs )
-      . "\n}});\n</script>";
+      . "\n}});\n]]>\n</script>";
 
     Foswiki::Func::addToZone( "script", "JQUERYPLUGIN::FOSWIKI::PREFERENCES",
         $text, "JQUERYPLUGIN::FOSWIKI" );

-- PiotrRoszatycki - 13 Mar 2013 (signature added after the fact)

Thanks for your contribution, but I'm not sure this is the way to go. Foswiki is served with a Content-Type of text/html; this tells browsers to render the document(s) as HTML, no matter the DOCTYPE. So, technically, the W3 validator is incorrect when it claims that the page is XHTML. It's actually HTML.

We can't change the Content-Type to the proper Content-Type for XHTML, namely application/xhtml+xml, without breaking compatibility with Internet Explorer 7 and 8, so we're pretty much stuck with HTML. If we wanted to make your change absolutely compatible with both XHTML and HTML, we'd have to jump through needle eyes as explained at http://wiki.whatwg.org/wiki/HTML_vs._XHTML#Element-specific_parsing...

Personally, I'd prefer focusing on HTML compatibility.

-- JanKrueger - 19 Mar 2013

This was pointed out in another task as well, and was addressed by encoding the two characters causing the issues.

-- GeorgeClark - 29 May 2014

Duplicate of Item12659 and Item12179

-- GeorgeClark - 29 May 2014
 

ItemTemplate edit

Summary JQueryPlugin emits the code which is not HTML compatible (does not pass validator.w3.org)
ReportedBy PiotrRoszatycki
Codebase trunk
SVN Range
AppliesTo Extension
Component
Priority Normal
CurrentState Duplicate
WaitingFor
Checkins
TargetRelease n/a
ReleasedIn n/a
CheckinsOnBranches
trunkCheckins
Release01x01Checkins
Topic revision: r4 - 29 May 2014, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy