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
|
||||
.provider('$Showdown', provider)
|
||||
.directive('sdModelToHtml', ['$Showdown', markdownToHtmlDirective])
|
||||
.directive('sdModelToHtml', ['$Showdown', '$sanitize', markdownToHtmlDirective])
|
||||
.filter('sdStripHtml', stripHtmlFilter);
|
||||
|
||||
/**
|
||||
|
@ -106,13 +106,13 @@ if (typeof angular !== 'undefined' && typeof Showdown !== 'undefined') {
|
|||
* @param $Showdown
|
||||
* @returns {*}
|
||||
*/
|
||||
function markdownToHtmlDirective($Showdown) {
|
||||
function markdownToHtmlDirective($Showdown, $sanitize) {
|
||||
|
||||
var link = function (scope, element) {
|
||||
scope.$watch('model', function (newValue) {
|
||||
var val;
|
||||
if (typeof newValue === 'string') {
|
||||
val = $Showdown.makeHtml(newValue);
|
||||
val = $sanitize($Showdown.makeHtml(newValue));
|
||||
} else {
|
||||
val = typeof newValue;
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ if (typeof angular !== 'undefined' && typeof Showdown !== 'undefined') {
|
|||
};
|
||||
}
|
||||
|
||||
})(angular.module('Showdown', []), Showdown);
|
||||
})(angular.module('Showdown', ['ngSanitize']), Showdown);
|
||||
|
||||
} else {
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user