Skip to content

Raise on missing closing quotes in matplotlibrc #22668

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

Merged
merged 1 commit into from
Mar 21, 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
7 changes: 6 additions & 1 deletion lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,12 @@ def _strip_comment(s):
elif 0 <= hash_pos < quote_pos:
return s[:hash_pos].strip()
else:
pos = s.find('"', quote_pos + 1) + 1 # behind closing quote
closing_quote_pos = s.find('"', quote_pos + 1)
if closing_quote_pos < 0:
raise ValueError(
f"Missing closing quote in: {s!r}. If you need a double-"
'quote inside a string, use escaping: e.g. "the \" char"')
pos = closing_quote_pos + 1 # behind closing quote


def is_writable_file_like(obj):
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/tests/test_cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@ def test_strip_comment(line, result):
assert cbook._strip_comment(line) == result


def test_strip_comment_invalid():
with pytest.raises(ValueError, match="Missing closing quote"):
cbook._strip_comment('grid.color: "aa')


def test_sanitize_sequence():
d = {'a': 1, 'b': 2, 'c': 3}
k = ['a', 'b', 'c']
Expand Down