From 0ed104a482536d2330d11f7a566ef5fe9e846eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Germade?= Date: Tue, 20 Feb 2018 00:37:57 +0100 Subject: [PATCH] deserialize replaces - by _ --- src/deserialize.js | 1 + tests/serialization-tests.js | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/deserialize.js b/src/deserialize.js index 1f23bff..8b35d66 100644 --- a/src/deserialize.js +++ b/src/deserialize.js @@ -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); } diff --git a/tests/serialization-tests.js b/tests/serialization-tests.js index 2f8baef..d400262 100644 --- a/tests/serialization-tests.js +++ b/tests/serialization-tests.js @@ -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',