Skip to content

Commit

Permalink
fix(linkify): include trailing slash in URL if present
Browse files Browse the repository at this point in the history
  • Loading branch information
tkohr committed Nov 28, 2023
1 parent ef6a273 commit 70c3a51
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { By } from '@angular/platform-browser'
import { GnUiLinkifyDirective } from './linkify.directive'

@Component({
template: `<div [gnUiLinkify]>Click this link https://www.example.com</div>`,
template: `<div [gnUiLinkify]>Click this link https://www.example.com/</div>`,
})
class TestComponent {}

Expand Down Expand Up @@ -32,7 +32,7 @@ describe('GnUiLinkifyDirective', () => {
const anchorElement = debugElement.query(By.css('a'))

const href = anchorElement.nativeElement.getAttribute('href')
expect(href).toBe('https://www.example.com')
expect(href).toBe('https://www.example.com/')
})

it('should have the target attribute set to "_blank"', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class GnUiLinkifyDirective implements OnInit {
}

private linkifyText(text: string): string {
return text.replace(/(\bhttps?:\/\/\S+\b)/g, (match) => {
return text.replace(/(\bhttps?:\/\/\S+\b\/?)/g, (match) => {
return `<a href="${match}" target="_blank"
class="text-primary cursor-pointer hover:underline">${match} <mat-icon class="material-symbols-outlined !w-[12px] !h-[14px] !text-[14px] opacity-75">open_in_new</mat-icon></a>`
})
Expand Down

0 comments on commit 70c3a51

Please sign in to comment.