Skip to content
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

Fix #2435: AttributeSanitizers are not applied to the child elements #2442

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,13 @@ export function sanitizeElement(
if (sanitizedElement) {
for (let child = element.firstChild; child; child = child.nextSibling) {
const newChild = isNodeOfType(child, 'ELEMENT_NODE')
? sanitizeElement(child, allowedTags, disallowedTags, styleSanitizers)
? sanitizeElement(
child,
allowedTags,
disallowedTags,
styleSanitizers,
attributeSanitizers
)
: isNodeOfType(child, 'TEXT_NODE')
? child.cloneNode()
: null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ describe('sanitizeElement', () => {
});

expect(result!.outerHTML).toBe('<div id="b"></div>');
expect(sanitizerSpy).toHaveBeenCalledTimes(1);
expect(sanitizerSpy).toHaveBeenCalledWith('a', 'div');
});

Expand All @@ -157,6 +158,27 @@ describe('sanitizeElement', () => {

expect(result!.outerHTML).toBe('<div></div>');
});

it('attributeCallbacks with child element', () => {
const element = document.createElement('div');
const child = document.createElement('span');
const sanitizerSpy = jasmine
.createSpy('sanitizer')
.and.callFake((value: string) => value + value);

element.id = 'a';
child.id = 'b';
element.appendChild(child);

const result = sanitizeElement(element, AllowedTags, DisallowedTags, undefined, {
id: sanitizerSpy,
});

expect(result!.outerHTML).toBe('<div id="aa"><span id="bb"></span></div>');
expect(sanitizerSpy).toHaveBeenCalledTimes(2);
expect(sanitizerSpy).toHaveBeenCalledWith('a', 'div');
expect(sanitizerSpy).toHaveBeenCalledWith('b', 'span');
});
});

describe('sanitizeHtml', () => {
Expand Down
Loading