Skip to content
This repository has been archived by the owner on Apr 17, 2022. It is now read-only.

Commit

Permalink
deserialize replaces - by _
Browse files Browse the repository at this point in the history
  • Loading branch information
jgermade committed Feb 19, 2018
1 parent e787dff commit 0ed104a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/deserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function _qsKey (o, keys, value) {
if( !Array.isArray(o) ) throw new Error('trying to assing empty key to non Array object');
o.push( _qsKey(keys[0] === '' ? [] : {}, keys, value) );
} else {
key = key.replace(/-/g, '_');
o[key] = _qsKey(o[key] || ( keys[0] === '' ? [] : {} ), keys, value);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/serialization-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ var serialization_dataset = [
data: { foo: 'bar', list: ['foo', 'bar'] },
},
{
qs: 'foo=bar&list[]=foo&list[]=bar&list[2]=hola',
formal_qs: 'foo=bar&list[]=foo&list[]=bar&list[]=hola',
data: { foo: 'bar', list: ['foo', 'bar', 'hola'] },
qs: 'foo=bar&list[]=foo&list[]=bar&list[2]=hola&foo-bar=gogogo',
formal_qs: 'foo=bar&list[]=foo&list[]=bar&list[]=hola&foo_bar=gogogo',
data: { foo: 'bar', list: ['foo', 'bar', 'hola'], foo_bar: 'gogogo' },
},
{
qs: 'foo=bar&list[]=foo&list[]=bar&list[2]first_name=Johnny&list[2]last_name=Boy',
Expand Down

0 comments on commit 0ed104a

Please sign in to comment.