Skip to content

Commit fe78726

Browse files
authored
Merge pull request #11492 from ret2libc/raise-file-parse-error-no-valueerr
Raise RequirementsFileParseError when missing closing quotation
2 parents 7311c82 + 3ca52dc commit fe78726

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

news/11491.bugfix.rst

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

src/pip/_internal/req/req_file.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,12 @@ def parse_line(line: str) -> Tuple[str, Values]:
393393

394394
args_str, options_str = break_args_options(line)
395395

396-
opts, _ = parser.parse_args(shlex.split(options_str), defaults)
396+
try:
397+
options = shlex.split(options_str)
398+
except ValueError as e:
399+
raise OptionParsingError(f"Could not split options: {options_str}") from e
400+
401+
opts, _ = parser.parse_args(options, defaults)
397402

398403
return args_str, opts
399404

tests/unit/test_req_file.py

+14
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,20 @@ def test_req_file_parse_comment_start_of_line(
786786

787787
assert not reqs
788788

789+
def test_invalid_options(self, tmpdir: Path, finder: PackageFinder) -> None:
790+
"""
791+
Test parsing invalid options such as missing closing quotation
792+
"""
793+
with open(tmpdir.joinpath("req1.txt"), "w") as fp:
794+
fp.write("--'data\n")
795+
796+
with pytest.raises(RequirementsFileParseError):
797+
list(
798+
parse_reqfile(
799+
tmpdir.joinpath("req1.txt"), finder=finder, session=PipSession()
800+
)
801+
)
802+
789803
def test_req_file_parse_comment_end_of_line_with_url(
790804
self, tmpdir: Path, finder: PackageFinder
791805
) -> None:

0 commit comments

Comments
 (0)