Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 011ac81

Browse files
authored
Merge pull request #22668 from timhoffm/fix-rcparam-quotes
Raise on missing closing quotes in matplotlibrc
2 parents 42b798c + c44ebd7 commit 011ac81

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,12 @@ 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(
418+
f"Missing closing quote in: {s!r}. If you need a double-"
419+
'quote inside a string, use escaping: e.g. "the \" char"')
420+
pos = closing_quote_pos + 1 # behind closing quote
416421

417422

418423
def is_writable_file_like(obj):

lib/matplotlib/tests/test_cbook.py

Lines changed: 5 additions & 0 deletions
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)