From 37c29a5c2bdbffde5011e646a811565acc42489a Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 27 Apr 2023 12:53:12 -0400 Subject: [PATCH] Improve gumbo error messages during tree construction adding punctuation, cleaning up whitespace, and naming the input tag If the message was: > 1:13: ERROR: This tag isn't allowed here Currently open tags: html, body, div, table. it is now something like: > 1:13: ERROR: Start tag 'svg' isn't allowed here. Currently open tags: html, body, div, table. --- gumbo-parser/src/error.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gumbo-parser/src/error.c b/gumbo-parser/src/error.c index 7b1480a263d..c26803b7634 100644 --- a/gumbo-parser/src/error.c +++ b/gumbo-parser/src/error.c @@ -91,7 +91,7 @@ static void print_tag_stack ( const GumboParserError* error, GumboStringBuffer* output ) { - print_message(output, " Currently open tags: "); + print_message(output, " Currently open tags: "); for (unsigned int i = 0; i < error->tag_stack.length; ++i) { if (i) { print_message(output, ", "); @@ -347,15 +347,19 @@ static void handle_parser_error ( if (error->parser_state == GUMBO_INSERTION_MODE_INITIAL) { print_message(output, "You must provide a doctype"); } else { - print_message(output, "Premature end of file"); + print_message(output, "Premature end of file."); print_tag_stack(error, output); } return; case GUMBO_TOKEN_START_TAG: + print_message(output, "Start tag '%s' isn't allowed here.", + gumbo_normalized_tagname(error->input_tag)); + print_tag_stack(error, output); + return; case GUMBO_TOKEN_END_TAG: - print_message(output, "That tag isn't allowed here"); + print_message(output, "Eng tag '%s' isn't allowed here.", + gumbo_normalized_tagname(error->input_tag)); print_tag_stack(error, output); - // TODO(jdtang): Give more specific messaging. return; } }