Repository navigation
Conversation
Form values of application/x-www-form-urlencoded and multipart/form-data
request bodies were run through JSON.parse, so string values that look
like JSON numbers were changed before serialization ('1.0' was sent as 1,
'1234567890123456789' lost precision). Only use the parsed value when it
is an object or an array.
Refs swagger-api#4136
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
buildRequestfor OAS3 runs everyapplication/x-www-form-urlencodedandmultipart/form-datavalue throughJSON.parse(added in #3482), so object fields that are passed as JSON text get decoded. The side effect is that string values which happen to be valid JSON primitives are converted to numbers/booleans first and then serialized back from that, which changes what is sent:'1.0'is sent as1,'5.0'as5'1234567890123456789'is sent as1234567890123456800(precision loss pastNumber.MAX_SAFE_INTEGER)This change keeps the parsed value only when it is an object or an array. For primitives the original value is used, which serializes to the same text it was passed as. Object/array fields passed as JSON text behave as before.
Motivation and Context
Refs #4136, see the reproduction by @DenyVeyten in the comments there (thanks also to @warappa for the original report). The same root cause is reported on the Swagger UI side in swagger-api/swagger-ui#10385 by @tsxalchemist and @ezi-ocb (string field with
5.0, long numeric IDs).The original report in #4136 (an object-typed field sent as JSON text being exploded by
style: form) is not changed by this PR.How Has This Been Tested?
Added tests in
test/oas3/execute/build-request.jsthat build urlencoded and multipart requests withid: '1234567890123456789',version: '1.0'and an object field passed as JSON text. Both fail onmain(id=1234567890123456800&version=1&...) and pass with the change.npx cross-env BABEL_ENV=commonjs jest --runInBand --config ./config/jest/jest.unit.config.js test/oas3 test/execute test/http test/swagger2 test/bugs: 24 suites, 358 passed. ESLint and Prettier are clean on the changed files.Screenshots (if appropriate):
Types of changes
package.json)Checklist:
Replaces #4292, which got closed when my fork was accidentally detached.