mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-09-17 14:21:14 +00:00
[ACS-10116] [ACA] Search page renders HTML from the Description,Title field instead of showing it as plain text
This commit is contained in:
@@ -133,8 +133,82 @@ describe('SearchResultsRowComponent', () => {
|
|||||||
|
|
||||||
it('should pass node to badge component', () => {
|
it('should pass node to badge component', () => {
|
||||||
component.context = { row: { node: nodeEntry } };
|
component.context = { row: { node: nodeEntry } };
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
const badgeElement = fixture.debugElement.query(By.css('aca-datatable-cell-badges'));
|
const badgeElement = fixture.debugElement.query(By.css('aca-datatable-cell-badges'));
|
||||||
expect(badgeElement).not.toBe(null);
|
expect(badgeElement).not.toBe(null);
|
||||||
expect(badgeElement.componentInstance.node).toBe(component.context.node);
|
expect(badgeElement.componentInstance.node).toBe(component.context.row.node);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should escape plain < and > in values', (done) => {
|
||||||
|
const customEntry: ResultSetRowEntry = {
|
||||||
|
entry: {
|
||||||
|
...nodeEntry.entry,
|
||||||
|
name: '2 < 5 > 3',
|
||||||
|
search: { score: 5 }
|
||||||
|
}
|
||||||
|
} as ResultSetRowEntry;
|
||||||
|
|
||||||
|
component.context = { row: { node: customEntry } };
|
||||||
|
component.name$
|
||||||
|
.asObservable()
|
||||||
|
.pipe(first())
|
||||||
|
.subscribe(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
const nameElement: HTMLSpanElement = fixture.debugElement.query(By.css('.aca-link.aca-crop-text')).nativeElement;
|
||||||
|
expect(nameElement.innerHTML).toBe('2 < 5 > 3');
|
||||||
|
expect(nameElement.textContent).toBe('2 < 5 > 3');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not render script tags as HTML', (done) => {
|
||||||
|
const customEntry: ResultSetRowEntry = {
|
||||||
|
entry: {
|
||||||
|
...nodeEntry.entry,
|
||||||
|
name: '<script>alert("xss")</script>',
|
||||||
|
search: { score: 5 }
|
||||||
|
}
|
||||||
|
} as ResultSetRowEntry;
|
||||||
|
|
||||||
|
component.context = { row: { node: customEntry } };
|
||||||
|
component.name$
|
||||||
|
.asObservable()
|
||||||
|
.pipe(first())
|
||||||
|
.subscribe(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
const nameElement: HTMLSpanElement = fixture.debugElement.query(By.css('.aca-link.aca-crop-text')).nativeElement;
|
||||||
|
expect(nameElement.innerHTML).toContain('<script>alert("xss")</script>');
|
||||||
|
expect(nameElement.textContent).toBe('<script>alert("xss")</script>');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow highlight spans but escape other tags', (done) => {
|
||||||
|
const customEntry: ResultSetRowEntry = {
|
||||||
|
entry: {
|
||||||
|
...nodeEntry.entry,
|
||||||
|
name: '<b><span class="aca-highlight">BoldHighlight</span></b>',
|
||||||
|
search: { score: 5 }
|
||||||
|
}
|
||||||
|
} as ResultSetRowEntry;
|
||||||
|
|
||||||
|
component.context = { row: { node: customEntry } };
|
||||||
|
component.name$
|
||||||
|
.asObservable()
|
||||||
|
.pipe(first())
|
||||||
|
.subscribe(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
const nameElement: HTMLSpanElement = fixture.debugElement.query(By.css('.aca-link.aca-crop-text')).nativeElement;
|
||||||
|
expect(nameElement.innerHTML).toBe('<b><span class="aca-highlight">BoldHighlight</span></b>');
|
||||||
|
expect(nameElement.textContent).toBe('<b>BoldHighlight</b>');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user