Browse Source

Merge pull request #2 from Tanmaykaturi/fix/semgrep-insecure-document-method-226-by7hB1CA35

fix: semgrep-insecure-document-method
pull/14743/head
Tanmaykaturi 6 months ago
committed by GitHub
parent
commit
ab7d04f4d3
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 28
      docs/en/docs/js/termynal.js

28
docs/en/docs/js/termynal.js

@ -222,13 +222,35 @@ class Termynal {
*/ */
lineDataToElements(lineData) { lineDataToElements(lineData) {
return lineData.map(line => { return lineData.map(line => {
let div = document.createElement('div'); let span = document.createElement('span');
div.innerHTML = `<span ${this._attributes(line)}>${line.value || ''}</span>`; span.textContent = line.value || '';
this._setAttributes(span, line);
return div.firstElementChild; return span;
}); });
} }
/**
* Helper function for safely setting attributes on element.
*
* @param {Element} element - The element to set attributes on.
* @param {Object} line - Line data object.
*/
_setAttributes(element, line) {
for (let prop in line) {
// Custom add class
if (prop === 'class') {
element.className = line[prop];
continue;
}
if (prop === 'type') {
element.setAttribute(this.pfx, line[prop]);
} else if (prop !== 'value') {
element.setAttribute(`${this.pfx}-${prop}`, line[prop]);
}
}
}
/** /**
* Helper function for generating attributes string. * Helper function for generating attributes string.
* *

Loading…
Cancel
Save