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

Comments

Projects
None yet
2 participants
@domosapien

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

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

This comment has been minimized.

Show comment
Hide comment
@rodneyrehm

rodneyrehm Sep 19, 2014

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.

Member

rodneyrehm commented Sep 19, 2014

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

This comment has been minimized.

Show comment
Hide comment
@domosapien

domosapien Sep 22, 2014

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.

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

This comment has been minimized.

Show comment
Hide comment
@rodneyrehm

rodneyrehm Sep 22, 2014

Member

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

fixed it in master…

Member

rodneyrehm commented Sep 22, 2014

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

fixed it in master…

@rodneyrehm rodneyrehm closed this Sep 22, 2014

@rodneyrehm rodneyrehm added the Bug label Sep 22, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment