Edgewall Software
Modify

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#10877 closed defect (fixed)

Invalid JSON breaks custom query builder

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:

Fix a mistake resulting in invalid JSON data generated on the server with Python 2.4 or 2.5.

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":"!~"}]};

Attachments (0)

Change History (6)

comment:1 by Christian Boos, 12 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):

comment:2 by anonymous, 12 years ago

Yup, that does it!

comment:3 by Christian Boos, 12 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: newclosed

Applied in r11382.

comment:4 by Jun Omae, 12 years ago

Oooh. Sorry, I'm so stupid…. Thanks the reporter and Christian!!

in reply to:  4 comment:5 by Christian Boos, 12 years ago

Replying to jomae:

Oooh. Sorry, I'm so stupid…. Thanks the reporter and Christian!!

Well, I get most of the blame, given all the iterations I triggered… and my final review saying "perfect" ;-)

comment:6 by dale.miller@…, 12 years ago

I opened #10982 because this also needs to be done for 1.1, 1.0.x, and 1.1.x.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.