Skip to content

Commit

Permalink
Merge pull request #11492 from ret2libc/raise-file-parse-error-no-val…
Browse files Browse the repository at this point in the history
…ueerr

Raise RequirementsFileParseError when missing closing quotation
  • Loading branch information
pfmoore authored Oct 6, 2022
2 parents 7311c82 + 3ca52dc commit fe78726
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/11491.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Raise RequirementsFileParseError when parsing malformed requirements options that can't be sucessfully parsed by shlex.
7 changes: 6 additions & 1 deletion src/pip/_internal/req/req_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,12 @@ def parse_line(line: str) -> Tuple[str, Values]:

args_str, options_str = break_args_options(line)

opts, _ = parser.parse_args(shlex.split(options_str), defaults)
try:
options = shlex.split(options_str)
except ValueError as e:
raise OptionParsingError(f"Could not split options: {options_str}") from e

opts, _ = parser.parse_args(options, defaults)

return args_str, opts

Expand Down
14 changes: 14 additions & 0 deletions tests/unit/test_req_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,20 @@ def test_req_file_parse_comment_start_of_line(

assert not reqs

def test_invalid_options(self, tmpdir: Path, finder: PackageFinder) -> None:
"""
Test parsing invalid options such as missing closing quotation
"""
with open(tmpdir.joinpath("req1.txt"), "w") as fp:
fp.write("--'data\n")

with pytest.raises(RequirementsFileParseError):
list(
parse_reqfile(
tmpdir.joinpath("req1.txt"), finder=finder, session=PipSession()
)
)

def test_req_file_parse_comment_end_of_line_with_url(
self, tmpdir: Path, finder: PackageFinder
) -> None:
Expand Down

0 comments on commit fe78726

Please sign in to comment.