Skip to content

Commit

Permalink
Consider —data value as POST even if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
mittsh committed May 19, 2018
1 parent 2a12c24 commit 146fd77
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/CurlParser.js
Expand Up @@ -460,13 +460,12 @@ export default class CurlParser {
})
}

const arg = this._popArg()

// missing argument value, ignore
// get argument value, consider empty if missing
let arg = this._popArg()
if (!arg) {
return request
arg = ''
}

if (option === '--data' ||
option === '--data-raw' ||
option === '--data-binary') {
Expand All @@ -490,6 +489,9 @@ export default class CurlParser {
for (let i = 0; i < components.length; i++) {
const component = components[i]
let m = component.match(/^([^\=]+)(?:\=([\s\S]*))?$/)
if (!m) {
continue
}
request = request.set('body', request.get('body').push(new CurlKeyValue({
key: decodeURIComponent(m[1]),
value: (m[2] !== undefined ? decodeURIComponent(m[2]) : null)
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/CurlParser-test.js
Expand Up @@ -1727,7 +1727,7 @@ class TestCurlParser extends UnitTest {
`
this.__testCurlRequest(input, new CurlRequest({
url: 'https://httpbin.org/post',
method: 'GET',
method: 'POST',
headers: Immutable.OrderedMap({
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0",
"Accept": "application/json, text/javascript, */*; q=0.01",
Expand Down

0 comments on commit 146fd77

Please sign in to comment.