angular/angular.js — pull request #3020 by cwerner87 (2013-06-21 07:27:35+00:00)
Title: Fix to unexpected behavior when passing null or undefined to $location.search

When using $location.search, I made an error when attempting to clear a search value:

Erroneous Usage:

$location.search(null);
Proper Usage:

$location.search('myParam', null);

This winds up setting the entire search object to null and caused errors on subsequent calls to set a search parameter(since it was trying to set it on null).

While this was my accidental misuse of $location.search, I think calling

$location.search(null);
or

$location.search(undefined);
should reset the search object to an empty object. I made this minor change in location.js:

this.$$search = isString(search) ? parseKeyValue(search) : search || {};

This way, passing null or undefined would wipe out the entire search object. This is a more reasonable behavior than actually setting the search object to null or undefined. It also has the added benefit of not yielding difficult-to-trace errors if you later attempt to set a search parameter.