Skip to content

Support custom HTTP methods + leniently parse flattened cURLs - #99

Merged
VShingala merged 3 commits into
postmanlabs:developfrom
giridharvc7:fix/lenient-parsing-and-custom-methods
Jul 16, 2026
Merged

Support custom HTTP methods + leniently parse flattened cURLs#99
VShingala merged 3 commits into
postmanlabs:developfrom
giridharvc7:fix/lenient-parsing-and-custom-methods

Conversation

@giridharvc7

Copy link
Copy Markdown
Contributor

What

Two related cURL-import robustness fixes:

  1. Custom HTTP methods. Import previously rejected any method outside a hard-coded allow-list (GET, POST, …, QUERY). It now accepts any syntactically valid HTTP method token (RFC 7230 token), so custom methods like MKCOL, PROPPATCH, BREW import correctly. Methods that aren't valid tokens (e.g. containing a space) are still rejected.

  2. Lenient parsing of flattened multi-line cURLs. When a \-continued multi-line cURL is pasted onto a single line, the newline is lost but the backslash remains (... \ -X POST \ --data-raw '{}'). The shell treats \ as an escaped space and glues it to the next token, so the following flag was dropped and the request silently fell back to GET with the body lost. We now strip a backslash that is flanked by whitespace (a standalone continuation artifact). An intentionally escaped space inside a word (path\ with\ space) is left untouched.

Why

  • Follow-up to CUE-6938. Users pasting flattened cURLs saw imports silently degrade to GET — reported against QUERY but it affected every method identically.
  • The old allow-list also had a bug: a bare -X re-extraction clobbered a correctly-parsed method to empty, producing the confusing The method is not supported. error (blank method name).

Testing

  • Added tests: arbitrary custom method (MKCOL), glued form (-XPROPPATCH), flattened \ continuation, and updated the invalid-method test to a genuinely invalid token (BAD METHOD).
  • Full suite green: 123 passing, lint clean.

Generated with Claude Code

cURL import previously rejected any method outside a fixed allow-list and
silently mis-parsed multi-line cURLs that were flattened onto a single line
(leaving a stray `\` from the dropped line continuation).

- validateCurlRequest now accepts any syntactically valid HTTP method token
  (RFC 7230), so custom methods like MKCOL/PROPPATCH import correctly. Only
  the -XPOST glued form re-extracts the method, so a bare `-X` no longer
  clobbers a method parsed from a separate token (which produced the blank
  "The method  is not supported" error).
- sanitizeArgs strips a backslash flanked by whitespace, so a flattened
  `... \ -X POST` continuation still parses the following flags. An escaped
  space inside a word (path\ with\ space) is left untouched.

Co-Authored-By: Claude <noreply@anthropic.com>

@VShingala VShingala left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core changes looks good, only issue I see is related to support of flattened multi-line cURL which we don't gurantee supporting.

Comment thread src/lib.js Outdated
// (i.e. a standalone continuation artifact) so the following flag is parsed.
// An intentionally escaped space inside a word (e.g. `path\ with\ space`) has a
// non-whitespace char before the backslash and is left untouched.
string = string.replace(/(\s)\\(?=\s)/g, '$1 ');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be risky IMO, we're adding this logic assuming that we support flattened multi-line cURL. But these are inherently wrong cURLs itself.

Supporting this case result in existing valid usecase being broken.

@giridharvc7 Is it okay if we remove it? It shouldn't affect the core logic we added in this PR.

Only test case parse a flattened multi-line cURL with stray "\\ " line continuations should fail which anyway should since we can not gurantee importing incorrect cURL imports that don't itself work in bash.

Image

Comment thread test/conversion.test.js Outdated
});
});

it('parse a flattened multi-line cURL with stray "\\ " line continuations', function (done) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this based on above comment.

@VShingala
VShingala merged commit 6e9d33a into postmanlabs:develop Jul 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants