Re: Malformed JSON output format

There is another issue, which appears in both v0.8.{5,6} if you have  
doctype option set to HTML5 – "lastLine" JSON field isn't set sometimes:

           {
               "lastLine": ,

               "message": "The Content-Type was text/html. Using the  
HTML parser.",
               "messageid": "html5",
               "explanation": "...",
               "type": "info"
           },


  I guess, the same approach as the one used for the "lastColumn"  
field can be used:

--- json_output.tmpl.orig	2010-02-03 19:07:30.000000000 +0100
+++ json_output.tmpl	2010-02-03 19:07:54.000000000 +0100
@@ -10,7 +10,7 @@
      "messages": [
          <TMPL_LOOP NAME="file_errors">
            {
-              "lastLine": <TMPL_VAR NAME="line">,
+              <TMPL_IF NAME="line">"lastLine": <TMPL_VAR  
NAME="line">,</TMPL_IF>
                <TMPL_IF NAME="char">"lastColumn": <TMPL_VAR  
NAME="char">,</TMPL_IF>
                "message": <TMPL_VAR NAME="msg">,
                <TMPL_IF NAME="num">"messageid": "<TMPL_VAR  
NAME="num">",</TMPL_IF>

In our environment we're still using v0.8.5, since there is no  
official v0.8.6 release yet (or at least there is no validator-0_8_6- 
release tag). For the v0.8.5 branch I personally use this patch:

Index: share/templates/en_US/json_output.tmpl
===================================================================
RCS file: /sources/public/validator/share/templates/en_US/ 
json_output.tmpl,v
retrieving revision 1.1
diff -b -r1.1 json_output.tmpl
8d7
<
14,18c13,14
<               <TMPL_IF NAME="err_type_err">"type": "error",</TMPL_IF>
<               <TMPL_IF NAME="err_type_warn">"type": "info",
<               "subtype": "warning"</TMPL_IF>
<               "lastLine": "<TMPL_VAR NAME="line">",
<               "lastColumn": <TMPL_VAR NAME="char">,
---
 >               <TMPL_IF NAME="line">"lastLine": <TMPL_VAR  
NAME="line">,</TMPL_IF>
 >               <TMPL_IF NAME="char">"lastColumn": <TMPL_VAR  
NAME="char">,</TMPL_IF>
20,22c16,20
<               "messageid": <TMPL_VAR NAME="num">,
<               "explanation": "<TMPL_VAR ESCAPE="JS" NAME="expl">",
<           }
---
 >               <TMPL_IF NAME="num">"messageid": "<TMPL_VAR  
NAME="num">",</TMPL_IF>
 >               <TMPL_IF NAME="expl">"explanation": "<TMPL_VAR  
ESCAPE="JS" NAME="expl">",</TMPL_IF>
 >               "type": <TMPL_IF  
NAME="err_type_err">"error"<TMPL_ELSE>"info"<TMPL_IF  
NAME="err_type_warn">,
 >               "subtype": "warning"</TMPL_IF></TMPL_IF>
 >           }<TMPL_UNLESS NAME="__last__">,</TMPL_UNLESS>
24d21
<
30d26
<

We discussed similar patch with Ville Skytta, and he pointed, that  
ESCAPE="JS" part might be a flaw here. But I personally haven't seen  
any escaping issues so far.

On 28.01.2010, at 18:09, Ville Skyttä wrote:

> On Wednesday 27 January 2010, Yaroslav Samchuk wrote:
>> When requesting the JSON output, returned data seems to be malformed:
>
> That's right, it's a bug, AFAIK fixed in the upcoming 0.8.6 release.
> http://www.w3.org/Bugs/Public/show_bug.cgi?id=7000
>

Received on Wednesday, 3 February 2010 18:24:06 UTC