diff --git a/src/app/pipes/string/slugify.spec.ts b/src/app/pipes/string/slugify.spec.ts index 5d2ff94c..4e598508 100644 --- a/src/app/pipes/string/slugify.spec.ts +++ b/src/app/pipes/string/slugify.spec.ts @@ -16,4 +16,9 @@ describe('SlugifyPipe Tests', () => { expect(pipe.transform('Foo Bar Baz')).toEqual('foo-bar-baz'); expect(pipe.transform('UPPER CASE TEXT')).toEqual('upper-case-text'); }); + + it('Should slugify special strings', () => { + expect(pipe.transform('http://example.com/foo')).toEqual('http-example-com-foo'); + expect(pipe.transform(' http://example.com/foo ')).toEqual('http-example-com-foo'); + }); }); diff --git a/src/app/pipes/string/slugify.ts b/src/app/pipes/string/slugify.ts index 6d0e72eb..cf96f54d 100644 --- a/src/app/pipes/string/slugify.ts +++ b/src/app/pipes/string/slugify.ts @@ -6,7 +6,9 @@ export class SlugifyPipe implements PipeTransform { transform(str: string): string { return GeneralHelper.isString(str) - ? str.toLowerCase().replace(/\s+/g, '-') + ? str.toLowerCase().trim() + .replace(/[^\w\-]+/g, ' ') + .replace(/\s+/g, '-') : str; } }