From bf67801b59a96b4f765dade294fb0239845ae4e8 Mon Sep 17 00:00:00 2001
From: Liam Bigelow <40188355+bglw@users.noreply.github.com>
Date: Tue, 17 Dec 2024 20:29:07 +1300
Subject: [PATCH] Fix HTML encoding bug with inline metadata
---
...html-entities-in-inline-meta.toolproof.yml | 29 +++++++++++++++++++
pagefind/src/fossick/parser.rs | 2 +-
2 files changed, 30 insertions(+), 1 deletion(-)
create mode 100644 pagefind/integration_tests/characters/pagefind-handles-html-entities-in-inline-meta.toolproof.yml
diff --git a/pagefind/integration_tests/characters/pagefind-handles-html-entities-in-inline-meta.toolproof.yml b/pagefind/integration_tests/characters/pagefind-handles-html-entities-in-inline-meta.toolproof.yml
new file mode 100644
index 00000000..c8fae3f8
--- /dev/null
+++ b/pagefind/integration_tests/characters/pagefind-handles-html-entities-in-inline-meta.toolproof.yml
@@ -0,0 +1,29 @@
+name: Character Tests > Pagefind handles HTML entities in inline meta
+steps:
+ - ref: ./background.toolproof.yml
+ - step: I have a "public/apiary/index.html" file with the content {html}
+ html: >-
+
the bees
+ - macro: I run Pagefind
+ - step: stdout should contain "Running Pagefind"
+ - step: The file "public/pagefind/pagefind.js" should not be empty
+ - step: I serve the directory "public"
+ - step: In my browser, I load "/"
+ - step: In my browser, I evaluate {js}
+ js: >-
+ let pagefind = await import("/pagefind/pagefind.js");
+
+
+ let search = await pagefind.search("bees");
+
+
+ let pages = await Promise.all(search.results.map(r => r.data()));
+
+ document.querySelector('[data-result]').innerText = pages.map(p =>
+ p.meta.title).join(", ");
+ - step: In my browser, the console should be empty
+ - step: In my browser, I evaluate {js}
+ js: |-
+ let val = await toolproof.querySelector("[data-result]");
+ toolproof.assert_eq(val.innerHTML, `The "bees"`);
diff --git a/pagefind/src/fossick/parser.rs b/pagefind/src/fossick/parser.rs
index 6e98bf3b..c5e2b556 100644
--- a/pagefind/src/fossick/parser.rs
+++ b/pagefind/src/fossick/parser.rs
@@ -646,7 +646,7 @@ fn parse_attr_string(input: String, el: &Element) -> Vec {
impl DomParsingNode {
fn get_attribute_pair(&self, input: &str) -> Option<(String, String)> {
match input.split_once(':') {
- Some((filter, value)) => Some((filter.to_owned(), value.to_owned())),
+ Some((filter, value)) => Some((filter.to_owned(), normalize_content(&value))),
None => {
if self.current_value.is_empty() {
None