Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise RequirementsFileParseError when missing closing quotation #11492

Merged
merged 1 commit into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -397,7 +397,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