1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

Merge pull request #11492 from ret2libc/raise-file-parse-error-no-valueerr

Raise RequirementsFileParseError when missing closing quotation
This commit is contained in:
Paul Moore 2022-10-06 14:31:16 +01:00 committed by GitHub
commit fe78726b36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

1
news/11491.bugfix.rst Normal file
View file

@ -0,0 +1 @@
Raise RequirementsFileParseError when parsing malformed requirements options that can't be sucessfully parsed by shlex.

View file

@ -393,7 +393,12 @@ def get_line_parser(finder: Optional["PackageFinder"]) -> LineParser:
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

View file

@ -786,6 +786,20 @@ class TestParseRequirements:
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: