[jifty-devel] canonicalize_ ajax call not doing the right thing

Peter Mottram peter at sysnix.com
Tue Jan 15 11:58:15 EST 2008

On Mon, 14 Jan 2008, Shawn M Moore wrote:
> On Wed, Jan 09, 2008 at 12:27:47PM +0100, Peter Mottram wrote:
>> Jesse Vincent wrote:
>>> Peter Mottram wrote:
>>>> I'm seeing some weirdness when using canonicalize_ inside my model as
>>>> there is a difference between how the ajax call handles things (badly)
>>>> and how the final POST request handles things (correctly).
>>>> Here's an extract of the relevant parts of my model:
>>>> So the ajax validator sees an empty value! If I enter somthing nice and
>>>> simple like '45th e4' then the result via ajax is correct as it returns
>>>> '45THE4'.
>>>> Could someone please point me in the right direction as to where to
>>>> start poking around in the Jifty code?
>>> I'd definitely start with the firebug XmlHttpRequest logging to see
>>> what's being posted to the server. Is the problem on the js side or the
>>> perl side?
>> Checking with firebug shows a perl problem since the failing canonicalize
>> does not get an 'update' returned to js in the xml.
>>> From there, it should be pretty easy to add a model to the
>>> jifty TestApp and a small test file which reproduces the problem using
>>> Test::WWW:Mechanize. Once you've done that, send a patch to jifty-devel,
>>> and make it all our problem ;)
>> I have attached a patch which includes a test case which passes and also
>> one that fails. I added the tests to 06-validation.t rather than creating
>> a new test file - hope that is OK.
>> Cheers
>> PeteM
> Hi Pete,
> I looked into it, and the problem is specifically the ';' character. CGI
> is intepreting that as a delimiter (as per RFC 3986). That's why
> the canonicalize_column_1 method is being called with the empty string.
> Here's what the action's arguments looks like to Jifty:
> $HASH1 = {
>           f              => '',
>           "J:A-canontest"
>                          => 'TestApp::Action::CreateCanonTest',
>           "J:A:F-column_1-canontest"
>                          => '',
>           "J:VALIDATE"   => 1
> };
> This explains the test failures: the parameter needs to be '%3Bf'
> instead of ';f'. Changing that causes the two tests to pass.
> However, it doesn't explain the behavior you were seeing. jifty.js does
> percent-encode the parameter correctly. Are you running an old version?
> Does it fail on standalone?

Hi Shawn

I changed my test to use '%3Bf' instead of ';f' and the tests still fail. 
I was hoping that WWW::Mechanize would uri-encode on my behalf as I am a 
little lazy.

Running TestApp under jifty/server and testing the model shows the 
problem. Here is the (reformatted) dump from a wireshark sniff where I 
enter 's;s' into column_1 and then tab out to force ajax validation...

GET /__jifty/validator.xml?J%3AA-auto-7257d4d4ca7867f697721e448d295854-1=TestApp%3A%3AAction%3A%3ACreateCanonTest&J%3AA%3AF-column_1-auto-7257d4d4ca7867f697721e448d295854-1=s%3Bs&J%3AVALIDATE=1 
Host: localhost:8888
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20070505 (Debian- Galeon/2.0.2 (Debian 
package 2.0.2-4)
Accept: text/javascript, text/html, application/xml, text/xml, */*
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-15,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
X-Requested-With: XMLHttpRequest
X-Prototype-Version: 1.6.0
Cookie: netdisco=c0c89852404241f655434ac1d551ec8c; style=null; 

HTTP/1.0 200 Jifty OK
Content-Type: text/xml; charset=UTF-8

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <validationaction id="J:A-auto-7257d4d4ca7867f697721e448d295854-1">
   <ignored id="errors-J:A:F-column_1-auto-7257d4d4ca7867f697721e448d295854-1" />
   <ignored id="warnings-J:A:F-column_1-auto-7257d4d4ca7867f697721e448d295854-1" />
  <canonicalizeaction id="J:A-auto-7257d4d4ca7867f697721e448d295854-1">
   <ignored name="J:A:F-column_1-auto-7257d4d4ca7867f697721e448d295854-1" />

This shows that the canonicalisation is failing. It works correctly with 
simple input but also fails for single quote characters (') although 
a test input with single quotes plus one or more alphanumeric chars is 

My jifty rev is pretty recent:

Last Changed Rev: 4800
Last Changed Date: 2008-01-08 06:57:18 +0100 (Tue, 08 Jan 2008)


More information about the jifty-devel mailing list