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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
25 additions and
3 deletions
-
docs/en/docs/js/termynal.js
|
|
|
@ -222,13 +222,35 @@ class Termynal { |
|
|
|
*/ |
|
|
|
lineDataToElements(lineData) { |
|
|
|
return lineData.map(line => { |
|
|
|
let div = document.createElement('div'); |
|
|
|
div.innerHTML = `<span ${this._attributes(line)}>${line.value || ''}</span>`; |
|
|
|
let span = document.createElement('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. |
|
|
|
* |
|
|
|
|