From a68119ef14208eb55aaea805149f9d3739d0a0b1 Mon Sep 17 00:00:00 2001 From: Folyd Date: Sun, 30 Oct 2022 22:03:54 +0800 Subject: [PATCH] Fix book index object field (`constructor`) conflicts bug --- extension/search/book.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/extension/search/book.js b/extension/search/book.js index 51e31912..55958127 100644 --- a/extension/search/book.js +++ b/extension/search/book.js @@ -1,6 +1,9 @@ class BookSearch { constructor(bookIndex) { - this.pages = {}; + // Create a empyt object with null prototype. + // This can prevent some weired bug, such as the key called `constructor`, + // this would conflict with the prototype constructor method! + this.pages = Object.create(null); bookIndex.forEach(({ name, url, pages }) => { pages.forEach(([title, path, parentTitles]) => { let cleanedTitle = cleanChapterTitle(title);