Add support for dropElements#37
Conversation
| FORBID_ATTR: dropAttrs, | ||
| }; | ||
| // https://github.com/cure53/DOMPurify/issues/556 | ||
| const isdropElementsSet = |
There was a problem hiding this comment.
I'm not sure but maybe deduce this boolean flag easier from within the default-assignment logic above, don't you think?
There was a problem hiding this comment.
I'm not sure but maybe deduce this boolean flag easier from within the default-assignment logic above, don't you think?
I'm probably missing something obvious here. But do you have an example of how to merge the initialization of the booleans with the assignments above?
There was a problem hiding this comment.
It seems we are checking if dropElements was set twice. Once in the dropElements = config.dropElements || [] line and then here. I'm wondering if those could be merged, to have the same semantic thing happen just once.
There was a problem hiding this comment.
Ah, I think I'm following! I'll try tackling this in #44, since that refactor will touch these lines as well (e.g. DEFAULT_DROP_ELEMENTS here will become a set)
mozfreddyb
left a comment
There was a problem hiding this comment.
I think this looks right, but at this point I really want tests 😂
| FORBID_ATTR: dropAttrs, | ||
| }; | ||
| // https://github.com/cure53/DOMPurify/issues/556 | ||
| const isdropElementsSet = |
There was a problem hiding this comment.
It seems we are checking if dropElements was set twice. Once in the dropElements = config.dropElements || [] line and then here. I'm wondering if those could be merged, to have the same semantic thing happen just once.
e471942 to
0c8f9d8
Compare
…t version from jsdelivr
0c8f9d8 to
38e1959
Compare
Resolves mozilla#30 Use DOMPurify `FORBID_CONTENTS` configuration to emulate the behavior we want from `dropElements` Example: ```javascript const sample = 'Some text <b><i>with</i></b> <blink><i>tags</i></blink>.' let testSanitizer = new Sanitizer({blockElements: ['blink'], dropElements: ['b']}) testSanitizer.sanitizeFor('p', 'Some text <b><i>with</i></b> <blink><i>tags</i></blink>.') // returns "<p>Some text <i>tags</i>.</p>" DOMPurify.sanitize(sample, { FORBID_CONTENTS: [ "b" ], FORBID_TAGS: ['b', 'blink']}); // returns "<p>Some text <i>tags</i>.</p>" ``` There might be some subtle bugs when the config contains elements in both `dropElements` and `blockElements` (see cure53/DOMPurify#556 (comment)). I'll work on setting up the test infra and come up with sample inputs to test this
38e1959 to
16a7d36
Compare
Resolves #30
Use DOMPurify
FORBID_CONTENTSconfiguration to emulate the behavior we want fromdropElementsExample:
Same example with DOMPurify 2.3.1
There might be some subtle bugs when the config contains elements in both
dropElementsandblockElements(see cure53/DOMPurify#556 (comment)). I'll work on setting up the test infra and come up with sample inputs to test this