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 <dstillman@zotero.org>
This commit is contained in:
abaevbog 2024-10-17 00:10:10 -07:00 committed by GitHub
parent 4c68f834c1
commit 1df2a96ae3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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];