Skip to content

Commit ac575d9

Browse files
authored
Merge pull request #5688 from DSpace/backport-5328-to-dspace-8_x
[Port dspace-8_x] Fix #2789: prevent linkify from converting words with dots into links
2 parents 5455e04 + 6110d31 commit ac575d9

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

src/app/shared/utils/markdown.directive.spec.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable max-classes-per-file */
12
import {
23
Component,
34
DebugElement,
@@ -20,6 +21,14 @@ import { MarkdownDirective } from './markdown.directive';
2021
})
2122
class TestComponent {}
2223

24+
@Component({
25+
template: `<div [dsMarkdown]="'Les informations demandés.es ne sont pas disponibles.'"></div>`,
26+
imports: [
27+
MarkdownDirective,
28+
],
29+
})
30+
class LinkifyTestComponent {}
31+
2332
describe('MarkdownDirective', () => {
2433
let fixture: ComponentFixture<TestComponent>;
2534

@@ -54,10 +63,9 @@ describe('MarkdownDirective sanitization with markdown disabled', () => {
5463
}).compileComponents();
5564
fixture = TestBed.createComponent(TestComponent);
5665
divEl = fixture.debugElement.query(By.css('div'));
57-
5866
});
5967

60-
it('should sanitize the script element out of innerHTML (markdown disabled)',() => {
68+
it('should sanitize the script element out of innerHTML (markdown disabled)', () => {
6169
fixture.detectChanges();
6270
divEl = fixture.debugElement.query(By.css('div'));
6371
expect(divEl.nativeElement.innerHTML).toEqual('test');
@@ -79,13 +87,37 @@ describe('MarkdownDirective sanitization with markdown enabled', () => {
7987
}).compileComponents();
8088
fixture = TestBed.createComponent(TestComponent);
8189
divEl = fixture.debugElement.query(By.css('div'));
82-
8390
});
8491

85-
it('should sanitize the script element out of innerHTML (markdown enabled)',() => {
92+
it('should sanitize the script element out of innerHTML (markdown enabled)', () => {
8693
fixture.detectChanges();
8794
divEl = fixture.debugElement.query(By.css('div'));
8895
expect(divEl.nativeElement.innerHTML).toEqual('test');
8996
});
9097

9198
});
99+
100+
describe('MarkdownDirective linkify with markdown enabled', () => {
101+
let fixture: ComponentFixture<LinkifyTestComponent>;
102+
let divEl: DebugElement;
103+
// Enable markdown
104+
environment.markdown.enabled = true;
105+
106+
beforeEach(async () => {
107+
await TestBed.configureTestingModule({
108+
providers: [
109+
{ provide: MathService, useClass: MockMathService },
110+
],
111+
}).compileComponents();
112+
fixture = TestBed.createComponent(LinkifyTestComponent);
113+
divEl = fixture.debugElement.query(By.css('div'));
114+
});
115+
116+
it('should not convert words with dots (e.g. demandés.es) to links (#2789)', async () => {
117+
fixture.detectChanges();
118+
await fixture.whenStable();
119+
divEl = fixture.debugElement.query(By.css('div'));
120+
expect(divEl.nativeElement.innerHTML).not.toContain('<a href');
121+
});
122+
123+
});

src/app/shared/utils/markdown.directive.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ export class MarkdownDirective implements OnInit, OnDestroy {
8686
html: true,
8787
linkify: true,
8888
});
89+
md.linkify.set({
90+
fuzzyLink: false,
91+
});
8992

9093
const html = alreadySanitized ? md.render(value) : this.sanitizer.sanitize(SecurityContext.HTML, md.render(value));
9194
this.el.innerHTML = html;

0 commit comments

Comments
 (0)