From 2ca7c0c226be73865988e550b81b309bc1da6ba0 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Thu, 1 Nov 2018 18:51:28 -0400 Subject: [PATCH] fix link parsing when having special characters --- .../databinded-text/databinded-text.component.spec.ts | 11 ++++++++++- .../databinded-text/databinded-text.component.ts | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app/components/stream/status/databinded-text/databinded-text.component.spec.ts b/src/app/components/stream/status/databinded-text/databinded-text.component.spec.ts index 7797d62e..a27ebcf0 100644 --- a/src/app/components/stream/status/databinded-text/databinded-text.component.spec.ts +++ b/src/app/components/stream/status/databinded-text/databinded-text.component.spec.ts @@ -67,6 +67,13 @@ describe('DatabindedTextComponent', () => { expect(component.processedText).toContain('

Test.
peertube.fr/videos/watch/69bb6

'); }); + it('should parse link with special character', () => { + const sample = `

Magnitude: 2.5 Depth: 3.4 km
Details: 2018/09/27 06:50:17 34.968N 120.685W
Location: 10 km (6 mi) W of Guadalupe, CA
Map: google.com/maps/place/34°58'4%
#EarthQuake #Quake #California

`; + + component.text = sample; + expect(component.processedText).toContain('google.com/maps/place/34°58\'4%'); + }); + it('should parse combined hashtag, mention and link', () => { const hashtag = 'programmers'; const hashtagUrl = 'https://test.social/tags/programmers'; @@ -92,10 +99,12 @@ describe('DatabindedTextComponent', () => { expect(component.processedText).toContain('bla1'); }); - it('shoult parse mention - Pleroma in Mastodon', () => { + it('should parse mention - Pleroma in Mastodon', () => { const sample = `
@kaniini @Gargron bla1?
`; component.text = sample; expect(component.processedText).toContain('
bla1?
'); }); + + }); diff --git a/src/app/components/stream/status/databinded-text/databinded-text.component.ts b/src/app/components/stream/status/databinded-text/databinded-text.component.ts index 67fb060a..3b6d6b8f 100644 --- a/src/app/components/stream/status/databinded-text/databinded-text.component.ts +++ b/src/app/components/stream/status/databinded-text/databinded-text.component.ts @@ -176,7 +176,7 @@ export class DatabindedTextComponent implements OnInit { } private getClassNameForLink(value: string): string { - let res = value.replace(/[.,\/#?!@$%+\^&\*;:{}=\-_`~()]/g, ""); + let res = value.replace(/[.,\/#?!@°$%+\'\^&\*;:{}=\-_`~()]/g, ""); return `link-${res}`; }