@@ -32,6 +32,26 @@ $(document).ready(function () {
3232 sidebarSearchWidget . attr ( 'data-widget-disabled' , 'true' ) ;
3333 }
3434
35+ /**
36+ * Escape a string for safe use inside HTML attribute values.
37+ * Converts characters that could break out of the attribute context
38+ * or be interpreted as HTML markup.
39+ *
40+ * @param {string } value
41+ * @returns {string }
42+ */
43+ function escapeHtmlAttribute ( value ) {
44+ if ( value == null ) {
45+ return '' ;
46+ }
47+ return String ( value )
48+ . replace ( / & / g, '&' )
49+ . replace ( / < / g, '<' )
50+ . replace ( / > / g, '>' )
51+ . replace ( / " / g, '"' )
52+ . replace ( / ' / g, ''' ) ;
53+ }
54+
3555 // Disabilita anche eventuali event listener di AdminLTE già attaccati
3656 searchInput . off ( '.adminlte.sidebar-search' ) ;
3757 searchInput . parent ( ) . off ( '.adminlte.sidebar-search' ) ;
@@ -279,7 +299,7 @@ $(document).ready(function () {
279299 // Sostituisci la classe highlight con search-highlight per coerenza
280300 processedLabels = processedLabels . replace ( / c l a s s = [ ' " ] h i g h l i g h t [ ' " ] / g, 'class="search-highlight"' ) ;
281301
282- const cleanLabels = labels . replace ( / < [ ^ > ] * > / g, '' ) ; // Rimuovi HTML per il tooltip
302+ const cleanLabels = escapeHtmlAttribute ( labels . replace ( / < [ ^ > ] * > / g, '' ) ) ; // Rimuovi HTML per il tooltip ed effettua l'escape per l'attributo
283303
284304 // Evidenzia il termine di ricerca nel titolo
285305 const highlightedTitle = highlightSearchTerm ( title , searchTerm ) ;
0 commit comments