-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from shennyg/fix/escape-entities-craft4
Escape HTML entities in log files for Craft 4
- Loading branch information
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,43 @@ function ($var) { | |
CSS; | ||
|
||
$js = <<<JS | ||
/** Mixin to extend the String type with a method to escape unsafe characters | ||
* for use in HTML. Uses OWASP guidelines for safe strings in HTML. | ||
* | ||
* Credit: http://benv.ca/2012/10/4/you-are-probably-misusing-DOM-text-methods/ | ||
* https://github.com/janl/mustache.js/blob/16ffa430a111dc293cd9ed899ecf9da3729f58bd/mustache.js#L62 | ||
* | ||
* Maintained by [email protected] | ||
* | ||
* @license http://opensource.org/licenses/MIT | ||
* | ||
* @version 1.0 | ||
* | ||
* @mixin | ||
*/ | ||
(function(){ | ||
"use strict"; | ||
function escapeHtml() { | ||
return this.replace(/[&<>"'\/]/g, function (s) { | ||
var entityMap = { | ||
"&": "&", | ||
"<": "<", | ||
">": ">", | ||
'"': '"', | ||
"'": ''', | ||
"/": '/' | ||
}; | ||
return entityMap[s]; | ||
}); | ||
} | ||
if (typeof(String.prototype.escapeHtml) !== 'function') { | ||
String.prototype.escapeHtml = escapeHtml; | ||
} | ||
})(); | ||
const logElem = document.getElementById("__log"); | ||
function streamLog (log) { | ||
|
@@ -75,7 +112,7 @@ function streamLog (log) { | |
}).then(data => data.text()).then(data => { | ||
let html = ""; | ||
data.split("\\n").forEach(line => { | ||
data.escapeHtml().split("\\n").forEach(line => { | ||
let m = /^(\d{4}(-\d{2}){2} (\d{2}:){2}\d{2}) (\[[^\]]+\]){3}\[([^\]]+)\]\[([^\]]+)\]/i.exec(line); | ||
if (m !== null) { | ||
let colour = ""; | ||
|