-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hotfix/issue 14 #17
Hotfix/issue 14 #17
Conversation
The directive was using the old attribute name "sdModelToHtml". Corrected to the appropriate value. Closes #14
…ressively sanitized
var showdownHTML = $showdown.makeHtml(newValue); | ||
val = $sce.trustAsHtml(showdownHTML); | ||
showdownHTML = $showdown.makeHtml(newValue); | ||
val = ($showdown.getOption('sanitize')) ? $sanitize(showdownHTML) : $sce.trustAsHtml(showdownHTML); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't run the code again, but in the non-sanitize case looks like ut is still broken. The old code is unchanged, but using $sce.trustAsHtml doesn't make any sense in this case. It would be used to pass the HTML as trusted to other directives, but that is not the case here. It is directly used in element.html(). IMHO there is no need for $sce at all here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a second thought: The difference might be that I use the full jQuery instead of the Angular jQuery light implementation. Has Angular's .element() different behavior here?
Ok, found the core issue why the code doesn't work for me: I am using full jQuery and not only the JQlite bundled with angular. In it seems In any way, I don't think you need
Does this make sense? |
One more thing: I just realized that showdown will not treat existing HTML (e.g. by stripping or escaping it). So in order to prevent dangerous user input it would actually make sense to always run
Not sure if there is a need for sanitizing the showdown output, but it could stay an option. The only bad thing showdown generates are probably the IDs, and there are already options to deal with that. |
Regarding the use of $sce, it enables decorating the directive without concerns of the output being incorrectly sanitized. However, it seems it break when using with jquery. @SyntaxRules thoughts? |
$sanitize breaks a lot more stuff than header ids. It parses img and a tags, which break under some edge cases. It also dislikes iframes (used in youtube showdow extension), strips unknown tags, etc... |
Yes, I personally don't see the point in using sanitize for the output. I think there is some misconception here, the whole issue is rather about the directive being broken when using jQuery. My comment above was about sanitizing the input before passing it to showdown, which would makes lot of sense, but could also be solved by showdownjs/showdown#182 . |
@SyntaxRules I think this is ready to merge. What do you think? |
@SyntaxRules I'm going to merge this pull as I need this and a couple of improvements. You can then improve over it with the changes you were talking about. |
Thanks! |
3 things in one: