Skip to content

Commit

Permalink
fixing .segment() to allow appending an empty element - closes #106
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Aug 13, 2013
1 parent b491e41 commit 2b60492
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ p.segment = function(segment, v, build) {
} else if (segment === null || segments[segment] === undefined) {
if (isArray(v)) {
segments = v;
} else if (v || (typeof v === "string" && v.length)) {
} else if (v || (typeof v === "string")) {
if (segments[segments.length -1] === "") {
// empty trailing elements have to be overwritten
// to prevent results such as /foo//bar
Expand Down
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,11 @@ test("segment", function() {

u.segment('test');
equal(u.path(), "/foo/test", "segment append trailing empty");

u.segment('');
equal(u.path(), "/foo/test/", "segment append empty trailing");
u.segment('');
equal(u.path(), "/foo/test/", "segment append empty trailing unchanged");
});
test("segmentCoded", function() {
var u = new URI("http://www.example.org/some%20thing/directory/foo.html"),
Expand All @@ -617,6 +622,11 @@ test("segmentCoded", function() {
equal(u.path(), "/hello%20world/mars/zapp%20zerapp", "segmentCoded del 3 ''");
u.segmentCoded(2, null);
equal(u.path(), "/hello%20world/mars", "segmentCoded del 3 null");

u.segmentCoded('');
equal(u.path(), "/hello%20world/mars/", "segmentCoded append empty trailing");
u.segmentCoded('');
equal(u.path(), "/hello%20world/mars/", "segmentCoded append empty trailing unchanged");
});

module("mutating query strings");
Expand Down

0 comments on commit 2b60492

Please sign in to comment.