Skip to content

Commit

Permalink
fix(Slugify pipe): issue (danrevah#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
danrevah committed Jan 26, 2017
1 parent 509cb47 commit 376cff7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/app/pipes/string/slugify.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
4 changes: 3 additions & 1 deletion src/app/pipes/string/slugify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 376cff7

Please sign in to comment.