Update JSON loader in search tests

This commit is contained in:
Guillaume Gomez 2025-04-02 21:03:01 +02:00
parent 0ed1cbe486
commit 7acc7a03a8

View file

@ -773,9 +773,10 @@ mod search {
fn read_book_index(root: &Path) -> serde_json::Value {
let index = root.join("book/searchindex.js");
let index = fs::read_to_string(index).unwrap();
let index = index.trim_start_matches("Object.assign(window.search, ");
let index = index.trim_end_matches(");");
serde_json::from_str(index).unwrap()
let index = index.trim_start_matches("window.search = JSON.parse('");
let index = index.trim_end_matches("');");
// We need unescape the string as it's supposed to be an escaped JS string.
serde_json::from_str(&index.replace("\\'", "'").replace("\\\\", "\\")).unwrap()
}
#[test]