summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb/Parser/Entities.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-06-10 10:34:28 +0200
committerAndreas Kling <kling@serenityos.org>2020-06-10 10:34:28 +0200
commite836f09094317c8eb1f9674d114cf34837b94e30 (patch)
treea60c4a75885cfe7c3c85ae6fa2a9d40e5d2a3927 /Libraries/LibWeb/Parser/Entities.cpp
parent43951f18e75d119a8e7c29327155d6b5eb493745 (diff)
downloadserenity-e836f09094317c8eb1f9674d114cf34837b94e30.zip
LibWeb: Fix parser interpreting "&quot;" as "&quot"
There was a logic mistake in the entity parser that chose the shorter matching entity instead of the longer. Fix this and make the entity lists constexpr while we're here.
Diffstat (limited to 'Libraries/LibWeb/Parser/Entities.cpp')
-rw-r--r--Libraries/LibWeb/Parser/Entities.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/Libraries/LibWeb/Parser/Entities.cpp b/Libraries/LibWeb/Parser/Entities.cpp
index 724468ec31..20b7d2750f 100644
--- a/Libraries/LibWeb/Parser/Entities.cpp
+++ b/Libraries/LibWeb/Parser/Entities.cpp
@@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <AK/LogStream.h>
#include <AK/StringView.h>
#include <LibWeb/Parser/Entities.h>
@@ -32,8 +33,8 @@ namespace HTML {
Optional<EntityMatch> codepoints_from_entity(const StringView& entity)
{
- struct {
- const char* entity;
+ constexpr struct {
+ StringView entity;
u32 codepoint;
} single_codepoint_entities[] = {
{ "AElig;", 0x000C6 },
@@ -2176,8 +2177,8 @@ Optional<EntityMatch> codepoints_from_entity(const StringView& entity)
{ "zwnj;", 0x0200C }
};
- struct {
- const char* entity;
+ constexpr struct {
+ StringView entity;
u32 codepoint1;
u32 codepoint2;
} double_codepoint_entities[] = {
@@ -2280,14 +2281,14 @@ Optional<EntityMatch> codepoints_from_entity(const StringView& entity)
for (auto& single_codepoint_entity : single_codepoint_entities) {
if (entity.starts_with(single_codepoint_entity.entity)) {
- if (match.entity.is_null() || entity.length() > match.entity.length())
- match = { { single_codepoint_entity.codepoint }, StringView(single_codepoint_entity.entity) };
+ if (match.entity.is_null() || single_codepoint_entity.entity.length() > match.entity.length())
+ match = { { single_codepoint_entity.codepoint }, single_codepoint_entity.entity };
}
}
for (auto& double_codepoint_entity : double_codepoint_entities) {
if (entity.starts_with(double_codepoint_entity.entity)) {
- if (match.entity.is_null() || entity.length() > match.entity.length())
+ if (match.entity.is_null() || double_codepoint_entity.entity.length() > match.entity.length())
match = EntityMatch { { double_codepoint_entity.codepoint1, double_codepoint_entity.codepoint2 }, StringView(double_codepoint_entity.entity) };
}
}