Edgewall Software
Modify

Opened 5 years ago

Closed 5 years ago

Last modified 5 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:
Release Notes:

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

API 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 Changed 5 years ago by Christian Boos

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 Changed 5 years ago by anonymous

Yup, that does it!

comment:3 Changed 5 years ago by Christian Boos

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

Applied in r11382.

comment:4 Changed 5 years ago by Jun Omae

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

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

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 Changed 5 years ago by dale.miller@…

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.
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.