debug help with rare unexpected output in js
<p>I have the following javascript on my page that is supposed to generate and go to a url instead of posting a form:</p>

<pre><code>var tokenList = ["auto", "usate"];
var dirList = [];

function makeUrl(prov, manuf, model, price){
  if (_addToken(prov)){
    _joinTokens();
  }
  if (_addToken(manuf)){
    _addToken(model);
    _joinTokens();
  }
  if (price){
    return _joinDirs() + "?prezzo=" + price;
  }
  return _joinDirs();
}

function _addToken(tok){
  if (tok){
    tokenList.push(tok.replace(/ /g,"_"));
    return true;
  }
  return false;
}
function _joinTokens(){
  dirList.push(tokenList.join('-'));
  tokenList = [];
}
function _joinDirs(){
  if (tokenList){
    _joinTokens();
  }
  var url = '/' + dirList.join('/');
  if (url.charAt(url.length-1) == '/'){
    url = url.slice(0, -1);
  }
  return url;
}
</code></pre>

<p>It's triggered by this code:</p>

<pre><code>$(document).ready(function(){
  $('#navForm').submit(function() {
    var prov = $("[name=select-provincia]").val();
    var manuf = $("[name=select-marca]").val();
    var model = $("[name=select-modello]").val();
    var price = $("[name=select-prezzo]").val();
    var url = makeUrl(prov, manuf, model, price);
    window.location = url;
    return false;
  });
});
</code></pre>

<p>It's been a long while since I translated this code from its original python. I've been getting rare errors in my server logs occasionally that show users trying to visit strange urls that look almost like two urls concatenated. I haven't been able to ever duplicate such an error, but my best guess is that there is something going on with my javascript. The last two times I got this error I noticed that the user was using firefox 3.6 and iphone. Could this be some kind of browser incompatibility? Is there anything wrong with my javascript at all? Is the error just in userland?</p>

<p>For reference here is an example wrong url:</p>

<p><code>/auto-usate-pesaro_e_urbino/fiat-500//rimini/fiat-500?prezzo=13000</code></p>

<p>and two possible correct ones:</p>

<p><code>/auto-usate-pesaro_e_urbino/fiat-500?prezzo=13000</code></p>

<p><code>/auto-usate-rimini/fiat-500?prezzo=13000</code></p>

<p>Any unrelated suggestions for optimizing the code are welcome since I am bad at this.</p>
