Skip to content

Commit

Permalink
test(segment): adding trim-slashes tests for all code-paths, #253
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Oct 5, 2015
1 parent 1374ddf commit d70d8b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@
}

function trimSlashes(text) {
var noLeadTrailSlashRegex = /^\/+|\/+$/g;
return text.replace(noLeadTrailSlashRegex, '');
var trim_expression = /^\/+|\/+$/g;
return text.replace(trim_expression, '');
}

URI._parts = function() {
Expand Down
8 changes: 7 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,13 @@

u = new URI('https://google.com')
u.segment('//font.ttf//');
equal(u.path(), '/font.ttf', 'segment removes trailing and leading');
equal(u.path(), '/font.ttf', 'segment removes trailing and leading slashes');

u.segment(['/hello', '/world/', '//foo.html']);
equal(u.path(), '/hello/world/foo.html', 'segment set array trimming slashes');

u.segment(1, '/mars/');
equal(u.path(), '/hello/mars/foo.html', 'segment set index trimming slashes');
});
test('segmentCoded', function() {
var u = new URI('http://www.example.org/some%20thing/directory/foo.html'),
Expand Down

0 comments on commit d70d8b8

Please sign in to comment.