Edgewall Software

Opened 10 years ago

Last modified 9 years ago

#10877 closed defect

Invalid JSON breaks custom query builder — at Version 1

Reported by: michael@… Owned by: Christian Boos
Priority: high Milestone: 0.12.5
Component: query system Version: 0.12dev
Severity: major Keywords: javascript to_js_string
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Christian Boos)

I just upgraded from 0.11.6 to 0.12.4 (and now 0.12.5dev-r11368) and am now getting a javascript syntax error on the custom query page. The offending javascript is the following:

var modes={"id":[{"name":"is","value":},{"name":"is not","value":"!"}],"select":[{"name":"is","value":},{"name":"is not","value":"!"}],"text":[{"name":"contains","value":"~"},{"name":"doesn't contain","value":"!~"},{"name":"begins with","value":"^"},{"name":"ends with","value":"$"},{"name":"is","value":},{"name":"is not","value":"!"}],"textarea":[{"name":"contains","value":"~"},{"name":"doesn't contain","value":"!~"}]};

To be sure, I check the generated JSON on the Demo site running Trac 0.12.5dev-r11311. Sure enough, that JSON is valid:

var modes={"id":[{"name":"is","value":""},{"name":"is not","value":"!"}],"select":[{"name":"is","value":""},{"name":"is not","value":"!"}],"text":[{"name":"contains","value":"~"},{"name":"doesn't contain","value":"!~"},{"name":"begins with","value":"^"},{"name":"ends with","value":"$"},{"name":"is","value":""},{"name":"is not","value":"!"}],"textarea":[{"name":"contains","value":"~"},{"name":"doesn't contain","value":"!~"}]};

I wonder if this bug is related to the version of python (2.4.3) I am running, and is similar in scope to #10771.

  • json.txt

    2.6 2.4  
    1 var modes={"id":[{"name":"is","value":""},{"name":"is not","value":"!"}],"select":[{"name":"is","value":""},{"name":"is not","value":"!"}],"text":[{"name":"contains","value":"~"},{"name":"doesn't contain","value":"!~"},{"name":"begins with","value":"^"},{"name":"ends with","value":"$"},{"name":"is","value":""},{"name":"is not","value":"!"}],"textarea":[{"name":"contains","value":"~"},{"name":"doesn't contain","value":"!~"}]};
     1var modes={"id":[{"name":"is","value":},{"name":"is not","value":"!"}],"select":[{"name":"is","value":},{"name":"is not","value":"!"}],"text":[{"name":"contains","value":"~"},{"name":"doesn't contain","value":"!~"},{"name":"begins with","value":"^"},{"name":"ends with","value":"$"},{"name":"is","value":},{"name":"is not","value":"!"}],"textarea":[{"name":"contains","value":"~"},{"name":"doesn't contain","value":"!~"}]};

Change History (1)

comment:1 by Christian Boos, 10 years ago

Description: modified (diff)
Keywords: javascript to_js_string added
Owner: set to Christian Boos
Severity: normalmajor

Damn, you're right, we've made a blunder here.

  • trac/util/text.py

     
    114114    (conform to the JSON spec)
    115115    """
    116116    if not text:
    117         return ''
     117        return '""'
    118118    def replace(match):
    119119        return _js_quote[match.group(0)]
    120120    return '"%s"' % _js_string_re.sub(replace, text)
  • trac/util/tests/text.py

     
    7777                         to_js_string('\x02\x1e'))
    7878        self.assertEqual(r'"\u0026\u003c\u003e"',
    7979                         to_js_string('&<>'))
     80        self.assertEqual('""',
     81                         to_js_string(''))
     82        self.assertEqual('""',
     83                         to_js_string(None))
    8084
    8185
    8286class UnicodeQuoteTestCase(unittest.TestCase):
Note: See TracTickets for help on using tickets.