1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-21 01:39:04 +02:00

fix(menu-item): add step to sanitize string

This commit is contained in:
cvillasenor 2024-07-15 23:45:33 -06:00
parent 493b6bd520
commit 8114487c6e
2 changed files with 10 additions and 3 deletions

View File

@ -4,7 +4,7 @@
import ClickableComponent from '../clickable-component.js';
import Component from '../component.js';
import {createEl} from '../utils/dom.js';
import { containsHexCode } from '../utils/str.js';
import { containsHexCode, sanitizeString } from '../utils/str.js';
/** @import Player from '../player' */
@ -75,9 +75,11 @@ class MenuItem extends ClickableComponent {
textContent: this.localize(this.options_.label)
});
if (containsHexCode(menuItemEl.textContent)) {
const sanitizedString = sanitizeString(menuItemEl.textContent);
if (containsHexCode(sanitizedString)) {
// Replacement that allows innerHTML to be render properly.
menuItemEl.innerHTML = menuItemEl.textContent;
menuItemEl.innerHTML = sanitizedString;
}
// If using SVG icons, the element with vjs-icon-placeholder will be added separately.

View File

@ -64,3 +64,8 @@ export const titleCaseEquals = function(str1, str2) {
export const containsHexCode = (string) => {
return /[a-zA-Z\040]*(&#x[0-9a-fA-F]{2,4};)[a-zA-Z\040]*/.test(string);
};
export const sanitizeString = (string) => {
string = string.replace(/[^a-z0-9 áéíóúñü\&#;_]/gim, '');
return string.trim();
};