-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve serialising JSON to PHP-compatible query strings (#7339)
* Improve serialising JSON to PHP-compatible query strings (fixes #7086) * Fix an eslint issue (unused `map` method) * Update http-build-query to 0.7.0 * ServerSideRender: remove an over-scoped function and a default value for attributes * ServerSideRender: cleanup unused var (oups, linting..) * ServerSideRender: tests for `http-build-query` * allow null default for attributes
- Loading branch information
1 parent
a40ba57
commit 74842d0
Showing
4 changed files
with
619 additions
and
555 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import httpBuildQuery from 'http-build-query'; | ||
|
||
// The following tests are adapted to the behavior of http-build-query v0.7.0, | ||
// to help mitigating possible regressions in the upstream library. | ||
describe( 'http-build-query', function() { | ||
test( 'should return an empty string for empty input', function() { | ||
expect( httpBuildQuery( null ) ).toBe( '' ); | ||
expect( httpBuildQuery() ).toBe( '' ); | ||
expect( httpBuildQuery( {} ) ).toBe( '' ); | ||
} ); | ||
|
||
test( 'should format basic url params ', function() { | ||
expect( | ||
httpBuildQuery( { | ||
stringArg: 'test', | ||
nullArg: null, | ||
emptyArg: '', | ||
numberArg: 123, | ||
} ) | ||
).toBe( | ||
encodeURI( | ||
'stringArg=test&nullArg=&emptyArg=&numberArg=123' | ||
) | ||
); | ||
} ); | ||
|
||
test( 'should format object params ', function() { | ||
expect( | ||
httpBuildQuery( { | ||
objectArg: { | ||
stringProp: 'test', | ||
numberProp: 123, | ||
}, | ||
} ) | ||
).toBe( | ||
encodeURI( | ||
'objectArg[stringProp]=test&objectArg[numberProp]=123' | ||
) | ||
); | ||
} ); | ||
|
||
test( 'should format an array of objects', function() { | ||
expect( | ||
httpBuildQuery( { | ||
children: [ | ||
{ | ||
name: 'bobby', | ||
age: 12, | ||
sex: 'M', | ||
}, | ||
{ | ||
name: 'sally', | ||
age: 8, | ||
sex: 'F', | ||
}, | ||
], | ||
} ) | ||
).toBe( | ||
encodeURI( | ||
'children[0][name]=bobby&children[0][age]=12&children[0][sex]=M&children[1][name]=sally&children[1][age]=8&children[1][sex]=F' | ||
) | ||
); | ||
} ); | ||
} ); |
Oops, something went wrong.