Skip to content

Commit 1995432

Browse files
authored
Merge pull request #5328 from guillermo-escire/feature/2789
Fix #2789: prevent linkify from converting words with dots into links
2 parents ccf5ca2 + 02a0db2 commit 1995432

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,
@@ -21,6 +22,14 @@ import { MarkdownDirective } from './markdown.directive';
2122
})
2223
class TestComponent {}
2324

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

@@ -55,10 +64,9 @@ describe('MarkdownDirective sanitization with markdown disabled', () => {
5564
}).compileComponents();
5665
fixture = TestBed.createComponent(TestComponent);
5766
divEl = fixture.debugElement.query(By.css('div'));
58-
5967
});
6068

61-
it('should sanitize the script element out of innerHTML (markdown disabled)',() => {
69+
it('should sanitize the script element out of innerHTML (markdown disabled)', () => {
6270
fixture.detectChanges();
6371
divEl = fixture.debugElement.query(By.css('div'));
6472
expect(divEl.nativeElement.innerHTML).toEqual('test');
@@ -80,13 +88,37 @@ describe('MarkdownDirective sanitization with markdown enabled', () => {
8088
}).compileComponents();
8189
fixture = TestBed.createComponent(TestComponent);
8290
divEl = fixture.debugElement.query(By.css('div'));
83-
8491
});
8592

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

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

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

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

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

0 commit comments

Comments
 (0)