Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ gumbo_test_SOURCES = \
tests/tokenizer.cc \
tests/test_utils.cc \
tests/utf8.cc \
tests/vector.cc
tests/vector.cc \
tests/error.cc
gumbo_test_DEPENDENCIES = libgumbo.la
gumbo_test_LDADD = libgumbo.la

Expand Down
2 changes: 1 addition & 1 deletion src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static const char* find_last_newline(
// There may be an error at EOF, which would be a nul byte.
assert(*c || c == error_location);
}
return c == original_text ? c : c + 1;
return c == original_text || c == error_location ? c : c + 1;
}

// Finds the next newline in the original source buffer from a given byte
Expand Down
41 changes: 41 additions & 0 deletions tests/error.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "gumbo.h"
#include "parser.h"
#include "error.h"

#include <string>

#include "gtest/gtest.h"
#include "test_utils.h"

namespace {

class GumboErrorTest : public ::testing::Test {
protected:
GumboErrorTest() {}

virtual ~GumboErrorTest() {

}
};

TEST_F(GumboErrorTest, NewlineAfterLessThanSymbol) {
const GumboOptions *options = &kGumboDefaultOptions;
const char *input = "<\n";
size_t input_len = strlen(input);
GumboOutput *output = gumbo_parse_with_options(options, input, input_len);
GumboVector *errors = &output->errors;
GumboParser parser = { ._options = options };
GumboStringBuffer msg;

gumbo_string_buffer_init(&parser, &msg);
for (size_t i=0; i < errors->length; i++) {
GumboError *err = (GumboError *)errors->data[i];
gumbo_string_buffer_clear(&parser, &msg);
gumbo_caret_diagnostic_to_string(&parser, err, input, &msg);
}
gumbo_string_buffer_destroy(&parser, &msg);

gumbo_destroy_output(options, output);
}

}