Skip to content

Commit

Permalink
Do not rfc3986 escape JSON bodies
Browse files Browse the repository at this point in the history
Example {json:{}} or {body:{}, json:true}
Related to request#1315
Closes request#1395
  • Loading branch information
simov committed Feb 2, 2015
1 parent 3d309d2 commit 441ba7c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions request.js
Expand Up @@ -1428,15 +1428,15 @@ Request.prototype.json = function (val) {
if (self.body !== undefined) {
if (!/^application\/x-www-form-urlencoded\b/.test(self.getHeader('content-type'))) {
self.body = safeStringify(self.body)
} else {
self.body = rfc3986(self.body)
}
self.body = rfc3986(self.body)
if (!self.hasHeader('content-type')) {
self.setHeader('content-type', 'application/json')
}
}
} else {
self.body = safeStringify(val)
self.body = rfc3986(self.body)
if (!self.hasHeader('content-type')) {
self.setHeader('content-type', 'application/json')
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test-rfc3986.js
Expand Up @@ -28,11 +28,11 @@ function runTest (t, options) {
t.equal(data, 'rfc3986=%21%2A%28%29%27')
}
else {
t.equal(data, '{"rfc3986":"%21%2A%28%29%27"}')
t.equal(data, '{"rfc3986":"!*()\'"}')
}
}
if (typeof options.json === 'object') {
t.equal(data, '{"rfc3986":"%21%2A%28%29%27"}')
t.equal(data, '{"rfc3986":"!*()\'"}')
}

res.writeHead(200)
Expand Down

0 comments on commit 441ba7c

Please sign in to comment.