diff options
| author | Igor Minar | 2013-08-01 09:34:56 -0700 | 
|---|---|---|
| committer | Igor Minar | 2013-08-01 09:34:56 -0700 | 
| commit | 9c53d0769e045c76c29a18b6e2ff9709b3338a48 (patch) | |
| tree | ed559ec73c0aadd5702beae7ea339d678a574e41 | |
| parent | 90532f5e3c2016c99833a4dd779a5c4718c84f4d (diff) | |
| download | angular.js-9c53d0769e045c76c29a18b6e2ff9709b3338a48.tar.bz2 | |
revert: fix(location): fix parameter handling on search()
This reverts commit 90532f5e3c2016c99833a4dd779a5c4718c84f4d.
The commit contains references to minErr that are not available
in the stable branch.
| -rw-r--r-- | docs/content/error/location/wpt.ngdoc | 4 | ||||
| -rw-r--r-- | src/ng/location.js | 29 | ||||
| -rw-r--r-- | test/ng/locationSpec.js | 29 | 
3 files changed, 11 insertions, 51 deletions
| diff --git a/docs/content/error/location/wpt.ngdoc b/docs/content/error/location/wpt.ngdoc deleted file mode 100644 index 8b3b3b2a..00000000 --- a/docs/content/error/location/wpt.ngdoc +++ /dev/null @@ -1,4 +0,0 @@ -@ngdoc error -@name $location:wpt -@fullName Wrong parameter type -@description diff --git a/src/ng/location.js b/src/ng/location.js index 9ec6300f..e99137d5 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -349,24 +349,17 @@ LocationUrl.prototype = {     * @return {string} search     */    search: function(search, paramValue) { -    switch (arguments.length) { -      case 0: -        return this.$$search; -      case 1: -        if (isString(search)) { -          this.$$search = parseKeyValue(search); -        } else if (isObject(search)) { -          this.$$search = search; -        } else { -          throw $locationMinErr('wpt', 'First parameter of function must be string or an object.'); -        } -        break; -      default: -        if (paramValue == undefined || paramValue == null) { -          delete this.$$search[search]; -        } else { -          this.$$search[search] = paramValue; -        } +    if (isUndefined(search)) +      return this.$$search; + +    if (isDefined(paramValue)) { +      if (paramValue === null) { +        delete this.$$search[search]; +      } else { +        this.$$search[search] = paramValue; +      } +    } else { +      this.$$search = isString(search) ? parseKeyValue(search) : search;      }      this.$$compose(); diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index 0158bf61..b6efe783 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -78,35 +78,6 @@ describe('$location', function() {      }); -    it('search() should handle multiple value', function() { -      url.search('a&b'); -      expect(url.search()).toEqual({a: true, b: true}); - -      url.search('a', null); - -      expect(url.search()).toEqual({b: true}); - -      url.search('b', undefined); -      expect(url.search()).toEqual({}); -    }); - - -    it('search() should handle single value', function() { -      url.search('ignore'); -      expect(url.search()).toEqual({ignore: true}); -    }); - - -    it('search() should throw error an incorrect argument', function() { -      expect(function() { -        url.search(null); -      }).toThrow('[$location:wpt] First parameter of function must be string or an object.'); -      expect(function() { -        url.search(undefined); -      }).toThrow('[$location:wpt] First parameter of function must be string or an object.'); -    }); - -      it('hash() should change hash fragment', function() {        url.hash('new-hash');        expect(url.hash()).toBe('new-hash'); | 
