From 55afaa48a75620b037c99990a30e2f37d26c672f Mon Sep 17 00:00:00 2001 From: Camille Moinier Date: Mon, 8 Jan 2024 17:00:32 +0100 Subject: [PATCH 1/2] fix(dh): improve regex to avoid detecting end parenthesis --- libs/ui/elements/src/lib/metadata-info/linkify.directive.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/ui/elements/src/lib/metadata-info/linkify.directive.ts b/libs/ui/elements/src/lib/metadata-info/linkify.directive.ts index 24cbb95636..071feebb71 100644 --- a/libs/ui/elements/src/lib/metadata-info/linkify.directive.ts +++ b/libs/ui/elements/src/lib/metadata-info/linkify.directive.ts @@ -40,7 +40,7 @@ export class GnUiLinkifyDirective implements OnInit { if (url) { displayValue = this.createLink(displayValue, url) } else { - const urlRegex = /\bhttps?:\/\/\S+\b[=)/]?/g + const urlRegex = /\bhttps?:\/\/\S+?(?=[\s)|]|$)/g const matches = displayValue.match(urlRegex) if (matches && matches.length > 0) { From 4c0daffc1529762f0202d6aedab74c80f4b169f3 Mon Sep 17 00:00:00 2001 From: Camille Moinier Date: Tue, 9 Jan 2024 09:09:27 +0100 Subject: [PATCH 2/2] feat(dh): improve regex and tests --- .../elements/src/lib/metadata-info/linkify.directive.spec.ts | 4 ++++ libs/ui/elements/src/lib/metadata-info/linkify.directive.ts | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/ui/elements/src/lib/metadata-info/linkify.directive.spec.ts b/libs/ui/elements/src/lib/metadata-info/linkify.directive.spec.ts index 541c624526..b2ee24948f 100644 --- a/libs/ui/elements/src/lib/metadata-info/linkify.directive.spec.ts +++ b/libs/ui/elements/src/lib/metadata-info/linkify.directive.spec.ts @@ -51,6 +51,10 @@ const testingUrls = [ 'Thirteenth link http://foo.com/(something)?after=parens query params', 'http://foo.com/(something)?after=parens', ], + [ + 'Fourteenth link (http://foo.com/blah) in parenthesis', + 'http://foo.com/blah', + ], ] const testWithMultipleUrls = { diff --git a/libs/ui/elements/src/lib/metadata-info/linkify.directive.ts b/libs/ui/elements/src/lib/metadata-info/linkify.directive.ts index 071feebb71..6c0bcaa7d1 100644 --- a/libs/ui/elements/src/lib/metadata-info/linkify.directive.ts +++ b/libs/ui/elements/src/lib/metadata-info/linkify.directive.ts @@ -40,9 +40,9 @@ export class GnUiLinkifyDirective implements OnInit { if (url) { displayValue = this.createLink(displayValue, url) } else { - const urlRegex = /\bhttps?:\/\/\S+?(?=[\s)|]|$)/g - const matches = displayValue.match(urlRegex) + const urlRegex = /\bhttps?:\/\/(?:\([^\s()]+\)|[^\s()]+)+/g + const matches = displayValue.match(urlRegex) if (matches && matches.length > 0) { matches.forEach((match) => { url = match