summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2016-11-13 16:59:14 -0800
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2016-11-13 16:59:14 -0800
commit1e23402eb23adf4ecd6c1c6bc83ecf21c8e0a6cd (patch)
tree847f7cb9ad1db1e5ce21b344e05d0abc10d64f29
parent5ca7e7cffc53b2378d3d9eb5168458935ca21627 (diff)
Change status_end_element_mismatch to point to closing tag name
Previously the error offset pointed to the first mismatching character, which can be confusing especially if the start tag name is a prefix of the end tag name. Instead, move the offset to the first character of the name - that way it should be more obvious that the problem is that the entire name mismatches. Fixes #112.
-rw-r--r--src/pugixml.cpp8
-rw-r--r--tests/test_parse.cpp4
2 files changed, 7 insertions, 5 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index dc3e7be..f4fa792 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -3346,18 +3346,20 @@ PUGI__NS_BEGIN
{
++s;
+ mark = s;
+
char_t* name = cursor->name;
- if (!name) PUGI__THROW_ERROR(status_end_element_mismatch, s);
+ if (!name) PUGI__THROW_ERROR(status_end_element_mismatch, mark);
while (PUGI__IS_CHARTYPE(*s, ct_symbol))
{
- if (*s++ != *name++) PUGI__THROW_ERROR(status_end_element_mismatch, s);
+ if (*s++ != *name++) PUGI__THROW_ERROR(status_end_element_mismatch, mark);
}
if (*name)
{
if (*s == 0 && name[0] == endch && name[1] == 0) PUGI__THROW_ERROR(status_bad_end_element, s);
- else PUGI__THROW_ERROR(status_end_element_mismatch, s);
+ else PUGI__THROW_ERROR(status_end_element_mismatch, mark);
}
PUGI__POPNODE(); // Pop.
diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp
index f199eb9..ba45a45 100644
--- a/tests/test_parse.cpp
+++ b/tests/test_parse.cpp
@@ -1005,8 +1005,8 @@ TEST(parse_error_offset)
CHECK_OFFSET("<n></n $>", parse_default, status_bad_end_element, 7);
CHECK_OFFSET("<n></n", parse_default, status_bad_end_element, 5);
- CHECK_OFFSET("<no></na>", parse_default, status_end_element_mismatch, 8);
- CHECK_OFFSET("<no></nod>", parse_default, status_end_element_mismatch, 9);
+ CHECK_OFFSET("<no></na>", parse_default, status_end_element_mismatch, 6);
+ CHECK_OFFSET("<no></nod>", parse_default, status_end_element_mismatch, 6);
}
TEST(parse_result_default)