Skip to content

Commit

Permalink
conform with RFC 3986
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusU committed Mar 15, 2014
1 parent 63dc9f3 commit 9b6834e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions slug.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function slug(string, opts) {
}
char = char.replace(/^\s+|\s+$/g, '');
}
char = char.replace(/[^\w\s$\*\_\+~\.\(\)\'\"\!\-:@]/g, ''); // allowed
char = char.replace(/[^\w\s\-\.\_~]/g, ''); // allowed
result += char;
}
result = result.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces
Expand Down Expand Up @@ -127,4 +127,4 @@ if (typeof define !== 'undefined' && define.amd) { // AMD
root.slug = slug;
}

}(this));
}(this));
15 changes: 11 additions & 4 deletions test/slug.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe 'slug', ->
[slug 'foo] bar baz'].should.eql ['foo-bar-baz']

it 'should leave allowed chars', ->
allowed = ['*', '+', '~', '.', '(', ')', "'", '"', '!', ':', '@']
allowed = ['.', '_', '~']
for a in allowed
[slug "foo #{a} bar baz"].should.eql ["foo-#{a}-bar-baz"]

Expand Down Expand Up @@ -123,15 +123,22 @@ describe 'slug', ->

it 'should replace symbols', ->
char_map = {
'©':'(c)', 'œ': 'oe', 'Œ': 'OE', '': 'sum', '®': '(r)', '': '+',
'': '"', '': '"', '': "'", '': "'", '': 'd', 'ƒ': 'f', '': 'tm',
'': 'sm', '': '...', '˚': 'o', 'º': 'o', 'ª': 'a', '': '*',
'©':'c', 'œ': 'oe', 'Œ': 'OE', '': 'sum', '®': 'r',
'': 'd', 'ƒ': 'f', '': 'tm',
'': 'sm', '': '...', '˚': 'o', 'º': 'o', 'ª': 'a'
'': 'delta', '': 'infinity', '': 'love', '&': 'and', '|': 'or',
'<': 'less', '>': 'greater'
}
for char, replacement of char_map
[slug "foo #{char} bar baz"].should.eql ["foo-#{replacement}-bar-baz"]

it 'should strip symbols', ->
char_map = [
'', '', '', '', '', ''
]
for char in char_map
[slug "foo #{char} bar baz"].should.eql ["foo-bar-baz"]

it 'should replace unicode', ->
char_map = {
'':"radioactive",'':"skull-and-bones",'':"caduceus",
Expand Down

0 comments on commit 9b6834e

Please sign in to comment.