mirror of
https://github.com/videojs/video.js.git
synced 2025-01-02 06:32:07 +02:00
fix(menu-item): add step to sanitize string
This commit is contained in:
parent
493b6bd520
commit
8114487c6e
@ -4,7 +4,7 @@
|
|||||||
import ClickableComponent from '../clickable-component.js';
|
import ClickableComponent from '../clickable-component.js';
|
||||||
import Component from '../component.js';
|
import Component from '../component.js';
|
||||||
import {createEl} from '../utils/dom.js';
|
import {createEl} from '../utils/dom.js';
|
||||||
import { containsHexCode } from '../utils/str.js';
|
import { containsHexCode, sanitizeString } from '../utils/str.js';
|
||||||
|
|
||||||
/** @import Player from '../player' */
|
/** @import Player from '../player' */
|
||||||
|
|
||||||
@ -75,9 +75,11 @@ class MenuItem extends ClickableComponent {
|
|||||||
textContent: this.localize(this.options_.label)
|
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.
|
// 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.
|
// If using SVG icons, the element with vjs-icon-placeholder will be added separately.
|
||||||
|
@ -64,3 +64,8 @@ export const titleCaseEquals = function(str1, str2) {
|
|||||||
export const containsHexCode = (string) => {
|
export const containsHexCode = (string) => {
|
||||||
return /[a-zA-Z\040]*(&#x[0-9a-fA-F]{2,4};)[a-zA-Z\040]*/.test(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();
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user