File tree 2 files changed +11
-1
lines changed
2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -412,7 +412,12 @@ def _strip_comment(s):
412
412
elif 0 <= hash_pos < quote_pos :
413
413
return s [:hash_pos ].strip ()
414
414
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
416
421
417
422
418
423
def is_writable_file_like (obj ):
Original file line number Diff line number Diff line change @@ -424,6 +424,11 @@ def test_strip_comment(line, result):
424
424
assert cbook ._strip_comment (line ) == result
425
425
426
426
427
+ def test_strip_comment_invalid ():
428
+ with pytest .raises (ValueError , match = "Missing closing quote" ):
429
+ cbook ._strip_comment ('grid.color: "aa' )
430
+
431
+
427
432
def test_sanitize_sequence ():
428
433
d = {'a' : 1 , 'b' : 2 , 'c' : 3 }
429
434
k = ['a' , 'b' , 'c' ]
You can’t perform that action at this time.
0 commit comments