Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Fix UrlParams parsing when URL has no parameters. Add remove() and isEmpty() methods. #6246

Merged
merged 4 commits into from
Dec 23, 2013
Merged

Conversation

lkcampbell
Copy link
Contributor

This is a fix for issue #6008. It also adds remove() and isEmpty() methods to the UrlParams module.

@ghost ghost assigned redmunds Dec 14, 2013
});
} else {
self._store = {};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it's possible for this code could provide unexpected results for self._store. For example, if url ends with a ?. Also, if all search parameters are integers, then self._store would be an array.

I think it would be safest to initialize it to an empty object in all cases:

        self._store = {};

        if (searchString) {
            urlParams = searchString.split("&");

            urlParams.forEach(function (param) {
                p = param.split("=");
                self._store[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
            });
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@redmunds, I believe this is already addressed in the URLParams constructor, which initializes self._store to an empty object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the constructor made the call to parse() and parse() was private method, then I would agree. But parse() is public and can be called multiple times.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I missed comment until after my last commit. Let me look into it.

@redmunds
Copy link
Contributor

Done with review. This looks good. Just a few comments. Thanks for adding unit tests!

@redmunds
Copy link
Contributor

@lkcampbell What's the status of this one? I was waiting for you to add a few more unit tests.

@lkcampbell
Copy link
Contributor Author

@redmunds, I'm going to work on the update this weekend.

@lkcampbell
Copy link
Contributor Author

@redmunds, changes for code review committed.

It occurred to me as I was updating the edge cases that this code doesn't have any exception handling for seriously malformed URLs. Do you want me to address those cases as well or is this sufficient for now?

@redmunds
Copy link
Contributor

this code doesn't have any exception handling for seriously malformed URLs

Seems like this code should only handle "url params" (hence the name), so I think it's outside of the scope of this module, and don't need to worry about it.

@lkcampbell
Copy link
Contributor Author

@redmunds, added _store initialization into parse method. Code review changes committed.

@redmunds
Copy link
Contributor

Looks good. Merging.

redmunds added a commit that referenced this pull request Dec 23, 2013
Fix UrlParams parsing when URL has no parameters.  Add remove() and isEmpty() methods.
@redmunds redmunds merged commit b8d6411 into adobe:master Dec 23, 2013
@lkcampbell lkcampbell deleted the fix-6008 branch December 23, 2013 23:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants