Skip to content

Commit 2879418

Browse files
authored
Merge pull request #12 from shennyg/master
Escape unsafe HTML, this allows XML and HTML tags to display as text instead of render
2 parents 644e5e5 + c267ebe commit 2879418

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.0.6 - 2022-05-10
2+
### Fixed
3+
- Escape unsafe HTML, this allows XML and HTML tags to display as text instead of render
4+
15
## 3.0.5 - 2021-11-23
26
### Added
37
- Add truncate / delete buttons

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ether/logs",
33
"description": "Access logs from the CP",
4-
"version": "3.0.5",
4+
"version": "3.0.6",
55
"type": "craft-plugin",
66
"minimum-stability": "dev",
77
"require": {

src/Utility.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,43 @@ function ($var) {
6363
CSS;
6464

6565
$js = <<<JS
66+
/** Mixin to extend the String type with a method to escape unsafe characters
67+
* for use in HTML. Uses OWASP guidelines for safe strings in HTML.
68+
*
69+
* Credit: http://benv.ca/2012/10/4/you-are-probably-misusing-DOM-text-methods/
70+
* https://github.com/janl/mustache.js/blob/16ffa430a111dc293cd9ed899ecf9da3729f58bd/mustache.js#L62
71+
*
72+
* Maintained by [email protected]
73+
*
74+
* @license http://opensource.org/licenses/MIT
75+
*
76+
* @version 1.0
77+
*
78+
* @mixin
79+
*/
80+
(function(){
81+
"use strict";
82+
83+
function escapeHtml() {
84+
return this.replace(/[&<>"'\/]/g, function (s) {
85+
var entityMap = {
86+
"&": "&amp;",
87+
"<": "&lt;",
88+
">": "&gt;",
89+
'"': '&quot;',
90+
"'": '&#39;',
91+
"/": '&#x2F;'
92+
};
93+
94+
return entityMap[s];
95+
});
96+
}
97+
98+
if (typeof(String.prototype.escapeHtml) !== 'function') {
99+
String.prototype.escapeHtml = escapeHtml;
100+
}
101+
})();
102+
66103
const logElem = document.getElementById("__log");
67104
68105
function streamLog (log) {
@@ -75,7 +112,7 @@ function streamLog (log) {
75112
}).then(data => data.text()).then(data => {
76113
let html = "";
77114
78-
data.split("\\n").forEach(line => {
115+
data.escapeHtml().split("\\n").forEach(line => {
79116
let m = /^(\d{4}(-\d{2}){2} (\d{2}:){2}\d{2}) (\[[^\]]+\]){3}\[([^\]]+)\]\[([^\]]+)\]/i.exec(line);
80117
if (m !== null) {
81118
let colour = "";

0 commit comments

Comments
 (0)