fix(browser): Fix favorite entries for malformed and long names

Limit long named tabs
Also avoid breaking visualization by escaping HTML

fix: #4961
This commit is contained in:
Stefan Dunca 2022-03-10 13:09:39 +01:00 committed by Stefan Dunca
parent e5322276ec
commit c03cdef684
2 changed files with 17 additions and 1 deletions

View File

@ -32,7 +32,9 @@ RowLayout {
icon.source: imageUrl
icon.width: 24
icon.height: 24
text: name
// Limit long named tabs. StatusFlatButton is not well-behaved control
// implicitWidth doesn't work. Also avoid breaking visualization by escaping HTML
text: Utils.escapeHtml(Utils.elideIfTooLong(name, 40))
MouseArea {
anchors.fill: parent

View File

@ -697,6 +697,20 @@ QtObject {
return qsTr("now")
}
function elideIfTooLong(str, maxLength) {
return (str.length > maxLength) ? str.substr(0, maxLength-4) + '...' : str;
}
function escapeHtml(unsafeStr)
{
return unsafeStr
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}
// Leave this function at the bottom of the file as QT Creator messes up the code color after this
function isPunct(c) {
return /(!|\@|#|\$|%|\^|&|\*|\(|\)|_|\+|\||-|=|\\|{|}|[|]|"|;|'|<|>|\?|,|\.|\/)/.test(c)