From 427d9e62c34bd7398e9d2b081f44314e754d66b3 Mon Sep 17 00:00:00 2001 From: Eugene Zolenko Date: Wed, 24 Jul 2024 10:28:54 -0700 Subject: [PATCH] duplicate attributes take first value instead of last https://html.spec.whatwg.org/#attribute-name-state "if there is already an attribute on the token with the exact same name, then this is a duplicate-attribute parse error and the new attribute must be removed from the token." --- html_parser.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/html_parser.hpp b/html_parser.hpp index d8b6c07..bd87705 100644 --- a/html_parser.hpp +++ b/html_parser.hpp @@ -18,7 +18,7 @@ #include #include -#if __cplusplus <= 199711L +#if __cplusplus < 199711L #if linux #include #else @@ -408,7 +408,8 @@ class HtmlElement : public enable_shared_from_this { std::cerr << "WARN : attribute unexpected " << input << std::endl; } else if (input == ' ') { if (!k.empty()) { - attribute[k] = v; + if (!attribute.count(k)) + attribute[k] = v; k.clear(); } } else if (input == '=') { @@ -422,7 +423,8 @@ class HtmlElement : public enable_shared_from_this { case PARSE_ATTR_VALUE_BEGIN:{ if (input == '\t' || input == '\r' || input == '\n' || input == ' ') { if (!k.empty()) { - attribute[k] = v; + if (!attribute.count(k)) + attribute[k] = v; k.clear(); } state = PARSE_ATTR_KEY; @@ -440,7 +442,8 @@ class HtmlElement : public enable_shared_from_this { case PARSE_ATTR_VALUE_END: { if((quota && input == split) || (!quota && (input == '\t' || input == '\r' || input == '\n' || input == ' '))) { - attribute[k] = v; + if (!attribute.count(k)) + attribute[k] = v; k.clear(); v.clear(); state = PARSE_ATTR_KEY; @@ -455,7 +458,8 @@ class HtmlElement : public enable_shared_from_this { } if(!k.empty()){ - attribute[k] = v; + if (!attribute.count(k)) + attribute[k] = v; } //trim