Skip to content

Commit

Permalink
Fix: Crash when input curl command line is not welformated
Browse files Browse the repository at this point in the history
  • Loading branch information
hongquan committed Jan 31, 2020
1 parent 775ae8a commit 2c7fcc8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion curlipie/pie.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import shlex
import logging
import mimetypes
from shlex import quote
from collections import deque
Expand All @@ -12,6 +13,7 @@


REGEX_SINGLE_OPT = re.compile(r'-\w$')
logger = logging.getLogger(__name__)


@attr.s(auto_attribs=True)
Expand All @@ -32,7 +34,11 @@ def curl_to_httpie(cmd: str, long_option: bool = False) -> ConversionResult:
# The cmd can be multiline string, with escape symbols, shlex doesn't support it, so
# we should convert it to one-line first.
oneline = ''.join(cmd.splitlines())
cargs = shlex.split(oneline)
try:
cargs = shlex.split(oneline)
except ValueError as e:
logger.error('Failed to parse as shell command. Error: %s', e)
return ConversionResult(errors=[str(e)])
if not cargs:
return ConversionResult('')
if cargs[0] == 'curl':
Expand Down

0 comments on commit 2c7fcc8

Please sign in to comment.