# A Mongrel parsing bug: "&" and "&amp;"

**URL:** <https://www.ruby-forum.com/t/a-mongrel-parsing-bug-and-amp/143325>\
**Category:** Rails\
**Created:** [July 17, 2008, 12:09pm UTC](https://www.ruby-forum.com/t/a-mongrel-parsing-bug-and-amp/143325 "2008-07-17T12:09:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/439d5e/32.png) [@gavin](https://www.ruby-forum.com/u/gavin)\
**Post date:** [July 17, 2008, 12:09pm UTC](https://www.ruby-forum.com/t/a-mongrel-parsing-bug-and-amp/143325/1 "2008-07-17T12:09:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/439d5e/32.png) [@gavin](https://www.ruby-forum.com/u/gavin)\
**Post date:** [July 17, 2008, 2:19pm UTC](https://www.ruby-forum.com/t/a-mongrel-parsing-bug-and-amp/143325/2 "2008-07-17T14:19:08Z")

</div>

On 17 Jul 2008, at 11:09, Gavin wrote:

> 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

---

<div class="post-metadata">

**Author:** ![gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/439d5e/32.png) [@gavin](https://www.ruby-forum.com/u/gavin)\
**Post date:** [July 17, 2008, 3:58pm UTC](https://www.ruby-forum.com/t/a-mongrel-parsing-bug-and-amp/143325/3 "2008-07-17T15:58:31Z")

</div>

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

–  
Roderick van Domburg

> **[De domeinnaam Nedforce.nl is te koop.](http://www.nedforce.nl)**
>
> Deze mooie domeinnaam kan al over een paar minuten van jou zijn. Betalen gaat eenvoudig en vertrouwd via iDEAL. Direct na de betaling ontvang je de verhuiscode per e-mail en kun je aan de slag.

---

<div class="post-metadata">

**Author:** ![gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/439d5e/32.png) [@gavin](https://www.ruby-forum.com/u/gavin)\
**Post date:** [July 27, 2008, 12:14am UTC](https://www.ruby-forum.com/t/a-mongrel-parsing-bug-and-amp/143325/4 "2008-07-27T00:14:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/439d5e/32.png) [@gavin](https://www.ruby-forum.com/u/gavin)\
**Post date:** [July 17, 2008, 4:44pm UTC](https://www.ruby-forum.com/t/a-mongrel-parsing-bug-and-amp/143325/5 "2008-07-17T16:44:12Z")

</div>

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

On Jul 17, 3:58 am, Roderick van Domburg \<rails-mailing-l…@andreas-
