From 1df2a96ae343d4378f8d3051daeba470df17c31e Mon Sep 17 00:00:00 2001 From: abaevbog Date: Thu, 17 Oct 2024 00:10:10 -0700 Subject: [PATCH] Remove ascii control chars from rendered item title (#4764) Filter out ASCII control characters in renderItemTitle, since an error is thrown if those characters are present when the innerHTML of a tab name in tab bar is set via dangerouslySetInnerHTML. Fixes: #4758 --------- Co-authored-by: Dan Stillman --- chrome/content/zotero/xpcom/utilities_internal.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index 7010ee2096..7b67532742 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -2431,6 +2431,12 @@ Zotero.Utilities.Internal = { let nodeStack = targetNode ? [targetNode] : null; let textContent = ''; + // Inserting text with ASCII control character as innerHTML (e.g., in tabBar.jsx) can cause + // an error, so filter out control characters 0-31 and character 127 DEL + // + // https://forums.zotero.org/discussion/118779/special-characters-in-item-title-breaks-the-tab-bar + title = title.replace(/[\x00-\x1F\x7F]/g, ''); + for (let token of title.split(/(<[^>]+>)/)) { if (this._titleMarkup.hasOwnProperty(token)) { let markup = this._titleMarkup[token];