Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spurious initial slash in empty relative path when calling .path() accessor #82

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ for (_part in _parts) {

p.pathname = function(v, build) {
if (v === undefined || v === true) {
var res = this._parts.path || (this._parts.urn ? '' : '/');
var res = this._parts.path || (this._parts.hostname ? '/' : '');
return v ? URI.decodePath(res) : res;
} else {
this._parts.path = v ? URI.recodePath(v) : "/";
Expand Down
8 changes: 8 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ test("path", function() {
u.pathname('/~userhome/@mine;is %2F and/');
equal(u.pathname(), '/~userhome/@mine;is%20%2F%20and/', "path encoding");
equal(u.pathname(true), '/~userhome/@mine;is %2F and/', "path decoded");

u = new URI('/a/b/c/').relativeTo('/a/b/c/');
equal(u.pathname(), '', "empty relative path");
equal(u.toString(), '', "empty relative path to string");

u.pathname('/');
equal(u.pathname(), '/', "empty absolute path");
equal(u.toString(), '/', "empty absolute path to string");
});
test("query", function() {
var u = new URI("http://example.org/foo.html");
Expand Down