Skip to content

Commit ab6c413

Browse files
committed
Handle empty string
1 parent 53d3a32 commit ab6c413

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

edtf/parser/grammar.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,20 +343,22 @@ def f(toks):
343343
)
344344

345345

346-
def parse_edtf(str, parseAll=True, fail_silently=False, debug=None):
346+
def parse_edtf(input_string, parseAll=True, fail_silently=False, debug=None):
347347
if debug is None:
348348
debug = DEBUG_PYPARSING
349349
try:
350-
if not str:
350+
if not input_string:
351351
raise ParseException("You must supply some input text")
352-
p = edtfParser.parseString(str.strip(), parseAll)
352+
p = edtfParser.parseString(input_string.strip(), parseAll)
353353
if p:
354354
return p[0]
355355
except ParseException as err:
356356
if fail_silently:
357357
return None
358358
if debug:
359359
raise
360-
near_text = str[max(err.loc - 10, 0) : err.loc + 10]
360+
near_text = ""
361+
if input_string:
362+
near_text = input_string[max(err.loc - 10, 0) : err.loc + 10]
361363
full_msg = f"Error at position {err.loc}: Invalid input or format near '{near_text}'. Please provide a valid EDTF string."
362364
raise EDTFParseException(full_msg) from None

0 commit comments

Comments
 (0)