Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/handle-invalid-params'
Browse files Browse the repository at this point in the history
Merges #95
  • Loading branch information
mrwhizzy committed Feb 23, 2023
2 parents c2237ea + a296334 commit d0e9eb7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions spec/url_helper_spec.coffee
Expand Up @@ -163,6 +163,44 @@ describe 'URLHelper', ->

expect(@subject.getParamsFromUrl(url)).to.deep.equal(params)

context 'when contains a malformed param without a key', ->
it 'returns the proper JSON object', ->
url = "http://foo.bar?foo=bar&=xxxx&baz=qux"
params = { '': 'xxxx', foo: 'bar', baz: 'qux' }

expect(@subject.getParamsFromUrl(url)).to.deep.equal(params)

it 'returns the proper JSON object', ->
url = "http://foo.bar?=bar&=xxxx&foo=bar"
params = { '': 'xxxx', foo: 'bar' }

expect(@subject.getParamsFromUrl(url)).to.deep.equal(params)

it 'returns the proper JSON object', ->
url = "http://foo.bar?foo=bar&=xxxx&=zzzz"
params = { '': 'zzzz', foo: 'bar' }

expect(@subject.getParamsFromUrl(url)).to.deep.equal(params)

context 'when contains a malformed param without a value', ->
it 'returns the proper JSON object', ->
url = "http://foo.bar?foo=bar&xxxx=&baz=qux"
params = { xxxx: '', foo: 'bar', baz: 'qux' }

expect(@subject.getParamsFromUrl(url)).to.deep.equal(params)

it 'returns the proper JSON object', ->
url = "http://foo.bar?xxxx=&zzzz=&foo=bar"
params = { xxxx: '', zzzz: '', foo: 'bar' }

expect(@subject.getParamsFromUrl(url)).to.deep.equal(params)

it 'returns the proper JSON object', ->
url = "http://foo.bar?foo=bar&xxxx=&zzzz="
params = { xxxx: '', zzzz: '', foo: 'bar' }

expect(@subject.getParamsFromUrl(url)).to.deep.equal(params)

context 'when contains an escaped param name', ->
it 'replaces the given param', ->
url = "http://foo.bar?#{encodeURIComponent('ελλη=νικά')}=xxxx&foo=bar"
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/url_helper.coffee
Expand Up @@ -34,7 +34,7 @@ define ['settings'], (Settings)->
# https://stackoverflow.com/a/1099670/4375736
getParamsFromUrl: (url = Settings.url.current) ->
url = url.split('#')[0] # drop hash from url, if exists
regex = /[?&;](.+?)=([^&;]+)/g
regex = /[?&;](.*?)=([^&;]*)/g
params = {}

while match = regex.exec(url)
Expand Down

0 comments on commit d0e9eb7

Please sign in to comment.