A Mongrel parsing bug: "&" and "&"

When using url_for to send path to a script (such as with
auto_complete), multiple params are joined with the "&" code. For
example:

text_field_with_auto_complete :blog :post, {}, { :posts_path(:a =>
1, :b => 2), :method => :get }

Produces this script:

var blog_post_auto_completer = new Ajax.Autocompleter('blog_post',
'blog_post_auto_complete', '/posts.js?a=1&b=2', {method:'get'})

Notice that "&" in the path. When sent to the server, it get
parsed as "a=1" and "amp;b=2".

I think the script is correct because XHTML & to be coded as "&".
Is this a bug in Mongrel? Has anyone else dealt with this?

Gavin

When using url_for to send path to a script (such as with
auto_complete), multiple params are joined with the "&" code. For
example:

text_field_with_auto_complete :blog :post, {}, { :posts_path(:a =>
1, :b => 2), :method => :get }

Produces this script:

var blog_post_auto_completer = new Ajax.Autocompleter('blog_post',
'blog_post_auto_complete', '/posts.js?a=1&b=2', {method:'get'})

Notice that "&" in the path. When sent to the server, it get
parsed as "a=1" and "amp;b=2".

I think the script is correct because XHTML & to be coded as "&".
Is this a bug in Mongrel? Has anyone else dealt with this?

Not mongrel's fault. It doesn't know anything about & being encoded as & (that's just a detail of html/xml etc..., whereas mongrel just cares about http)
If anything it's probably the fault of text_field_with_auto_complete since if you're inside a cdata thing (like most javascript is) then you don't need to escape the &

Fred

Frederick Cheung wrote:

If anything it's probably the fault of text_field_with_auto_complete
since if you're inside a cdata thing (like most javascript is) then
you don't need to escape the &

Indeed it's quite likely you're double-escaping the ampersand. Closely
inspect the rendered HTML source to verify.

I can't reproduce this bug outside the plugin, so it does seem to be a
problem with auto_complete. It's strange because the generated path
looks fine:

Ajax.Autocompleter('blog_post', 'blog_post_auto_complete', '/posts.js?
a=1&b=2', {method:'get'})

This just gets sent to the index action, so that & is getting
gummed up somewhere between submit and the start of the action. But
where? This is a one-line hack to fix, but I'd rather see it working
correctly.

Gavin

Has anyone found a fix for this or can you explain a little more in
detail about your work around.

how do you get your second value in the controller? when i try

params[:amp;b]

i get an error (as expected).

i've messed around with this, but can't quite seem to get anywhere,
your help would be extremely appreciated