Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search(true) fails in FireFox #169

Closed
domosapien opened this issue Sep 19, 2014 · 3 comments
Closed

search(true) fails in FireFox #169

domosapien opened this issue Sep 19, 2014 · 3 comments
Labels

Comments

@domosapien
Copy link

The following code throws a TypeError (push is not a function) in FireFox:

var uriParser = new URI(document.URL),
      searchMap = uriParser.search(true);
@rodneyrehm
Copy link
Member

I'm afraid I cannot reproduce your issue - the test suite passes on my Firefox 32.0.2. Running your example code in the console works fine, too.

@domosapien
Copy link
Author

Alas, I'm afraid your code coverage is missing something then. I have now tested in both 32 and 33. I downloaded the non-minified URI.js and debugged it myself.

This was my test page:

<html>
<head>
<script type="text/javascript" src="./URI.js"></script>
</head>
<body>
<script type="text/javascript">
    var uriParser = new URI(document.URL),
        searchMap = null;
    try {
        // fails in FireFox
        searchMap = uriParser.search(true);
    } catch (ex) {
        var match,
            pl = /\+/g, // Regex for replacing addition symbol with a space
            search = /([^&=]+)=?([^&]*)/g,
            decode = function (s) {
                return decodeURIComponent(s.replace(pl, " "));
            },
            query = window.location.search.substring(1);

        searchMap = {};
        while (match = search.exec(query))
            searchMap[decode(match[1])] = decode(match[2]);
    }
</script>
</body>
</html>

I then invoked the page using '?watch=1' in Chrome (succeeds using URI) and Firefox (exception as before, uses the handler to parse the parameter correctly).

Using a debugger, I found the offending line in the function parseQuery on line 535 (current master). The code shouldn't get there in this case as the parameter doesn't exist in the items object yet, so line 530 is failing. In Chrome 'items[name]' returns false, but in Firefox it returns true. Using 'items[name] == true' (no ===, just to exclude falsey) instead yields the correct result.

@rodneyrehm
Copy link
Member

ah, man, … the problem is the watch, because Firefox adds .watch() to the prototype of every object.

fixed it in master…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants