Skip to content

Commit

Permalink
fix(menu-item): add step to sanitize string
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosVillasenor committed Jul 16, 2024
1 parent 493b6bd commit 8114487
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/js/menu/menu-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' */

Expand Down Expand Up @@ -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;

Check warning on line 82 in src/js/menu/menu-item.js

View check run for this annotation

Codecov / codecov/patch

src/js/menu/menu-item.js#L82

Added line #L82 was not covered by tests
}

// If using SVG icons, the element with vjs-icon-placeholder will be added separately.
Expand Down
5 changes: 5 additions & 0 deletions src/js/utils/str.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

0 comments on commit 8114487

Please sign in to comment.