Skip to content

Commit

Permalink
added a condition that checks for an ending reply from user delimiter…
Browse files Browse the repository at this point in the history
… to indicate malformed header information in the reply from user section
  • Loading branch information
benne238 committed Jun 30, 2021
1 parent d858c0c commit 56798fb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/webqueue2api/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,19 @@ def error_handler(original_string, match_start_index, tokens):
'datetime': format_date_string(str(datetime.datetime.now())),
}

if token_string == reply_from_user_start_delimiter:
if token_string == reply_from_user_start_delimiter and \
reply_from_user_end_delimiter in original_string[match_start_index:]:

expected_token = "\n\n"
line_number = original_string[:original_string[match_start_index:].find(reply_from_user_end_delimiter) + match_start_index].count("\n") + 1

parse_error["expected"] = expected_token
parse_error["got"] = reply_from_user_end_delimiter
parse_error["line_num"] = line_number
parsed_item.append(parse_error)
raise ParseError(line_number, f"No reply from user end delimiter found")

elif token_string == reply_from_user_start_delimiter:
expected_token = reply_from_user_end_delimiter
line_number = original_string.count('\n') + 1

Expand Down

0 comments on commit 56798fb

Please sign in to comment.