mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
Use angular's $sanitize to prevent XSS
Addresses https://github.com/showdownjs/showdown/issues/70 at least within angular.
This commit is contained in:
parent
eca8386dbb
commit
2b2eb972dd
|
@ -10,7 +10,7 @@ if (typeof angular !== 'undefined' && typeof Showdown !== 'undefined') {
|
||||||
|
|
||||||
module
|
module
|
||||||
.provider('$Showdown', provider)
|
.provider('$Showdown', provider)
|
||||||
.directive('sdModelToHtml', ['$Showdown', markdownToHtmlDirective])
|
.directive('sdModelToHtml', ['$Showdown', '$sanitize', markdownToHtmlDirective])
|
||||||
.filter('sdStripHtml', stripHtmlFilter);
|
.filter('sdStripHtml', stripHtmlFilter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,13 +106,13 @@ if (typeof angular !== 'undefined' && typeof Showdown !== 'undefined') {
|
||||||
* @param $Showdown
|
* @param $Showdown
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
function markdownToHtmlDirective($Showdown) {
|
function markdownToHtmlDirective($Showdown, $sanitize) {
|
||||||
|
|
||||||
var link = function (scope, element) {
|
var link = function (scope, element) {
|
||||||
scope.$watch('model', function (newValue) {
|
scope.$watch('model', function (newValue) {
|
||||||
var val;
|
var val;
|
||||||
if (typeof newValue === 'string') {
|
if (typeof newValue === 'string') {
|
||||||
val = $Showdown.makeHtml(newValue);
|
val = $sanitize($Showdown.makeHtml(newValue));
|
||||||
} else {
|
} else {
|
||||||
val = typeof newValue;
|
val = typeof newValue;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ if (typeof angular !== 'undefined' && typeof Showdown !== 'undefined') {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
})(angular.module('Showdown', []), Showdown);
|
})(angular.module('Showdown', ['ngSanitize']), Showdown);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user