Skip to content

Commit 89eb2d1

Browse files
committed
Raise on missing closing quotes in matplotlibrc
1 parent a2ddfc0 commit 89eb2d1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/matplotlib/cbook/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,10 @@ def _strip_comment(s):
412412
elif 0 <= hash_pos < quote_pos:
413413
return s[:hash_pos].strip()
414414
else:
415-
pos = s.find('"', quote_pos + 1) + 1 # behind closing quote
415+
closing_quote_pos = s.find('"', quote_pos + 1)
416+
if closing_quote_pos < 0:
417+
raise ValueError(f"Missing closing quote in: {s}")
418+
pos = closing_quote_pos + 1 # behind closing quote
416419

417420

418421
def is_writable_file_like(obj):

lib/matplotlib/tests/test_cbook.py

+5
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,11 @@ def test_strip_comment(line, result):
424424
assert cbook._strip_comment(line) == result
425425

426426

427+
def test_strip_comment_invalid():
428+
with pytest.raises(ValueError, match="Missing closing quote"):
429+
cbook._strip_comment('grid.color: "aa')
430+
431+
427432
def test_sanitize_sequence():
428433
d = {'a': 1, 'b': 2, 'c': 3}
429434
k = ['a', 'b', 'c']

0 commit comments

Comments
 (0)