Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Bug in validator for escaped double-quote

Help
jeroen
2013-12-22
2013-12-22
  • jeroen
    jeroen
    2013-12-22

    There is a bug in the JSON-validator related to escaped double quotes. All of the examples below are proper json (validated with jsonlint) and contain a properly escaped quote.

    I am using the RJSONIO package which is an interface to libjson for the R programming language. Here are examples. Note that when I input the escape I have to escape the backslash first. I use cat() to show the actual content of the json string. The first two examples return TRUE, correctly

    x = '["\\""]'
    cat(x, "\n")
     ["\""] 
    isValidJSON(x, asText=TRUE)
    [1] TRUE
    
    x = '["\\"123"]'
    cat(x, "\n")
     ["\"123"] 
    isValidJSON(x, asText=TRUE)
     [1] TRUE
    

    However, when the escaped quote is followed by a forward slash, suddenly validation returns FALSE, which is incorrect:

    x = '["\\"/"]'
    cat(x, "\n")
     ["\"/"] 
    isValidJSON(x, asText=TRUE)
     [1] FALSE
    

    Most surprisingly, also when exactly the same string as in the first example is used, but some white-space is added after the string, the validation fails:

    x = '["\\"" ]'
    cat(x, "\n")
     ["\"" ] 
    isValidJSON(x, asText=TRUE)
     [1] FALSE
    

    I think this might be related to a similar bug in the parser which was fixed last year: https://sourceforge.net/p/libjson/bugs/32/

     
    Last edit: jeroen 2013-12-24