Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
After some internal discussions, we identified a couple things that could be easily addressed to help developers using this library.
Issues addressed
The first issue identified was that as the
img
src
attribute contains URLs likea
href
attributes, we should sanitize the URLs the same way we do fora
href
. This addsimg
src
tag attribute to the built-in sanitization supporting our list of allowed protocols.The second thing identified that we need to break out the URL sanitization into a public method to make it possible to sanitize URLs according to the rules, without necessarily needing to extend the whitelist and/or define custom filtering options to sanitize tag attributes containing URI values. This update adds a public
sanitizeUrl
method, which we then reuse in our custom filtering option that handlesa
href
andimg
src
parsing.This update includes documentation and tests for the
sanitizeUrl
method as well as some cleanup to the tests for allowed protocols added in earlier enhancements.