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

Fixed bug whereby absoluteTo failed on a root base #200

Merged
merged 1 commit into from
Mar 31, 2015
Merged
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
1 change: 1 addition & 0 deletions src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,7 @@

if (resolved.path().charAt(0) !== '/') {
basedir = base.directory();
basedir = basedir ? basedir : base.path().indexOf('/') === 0 ? '/' : '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that reads horribly (not that my code reads any better…)
wondering if the following makes more sense

// either basedir is a thing, or path begins with /, defaults to empty string
basedir || base.path().slice(0, 1) === '/' && '/' || '';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know. It somehow seems that there should be a cleaner way to do this... :-) But I couldn't find it (admittedly,

As for changing the ?: to ||&& - that's a question of style. My code is more "say what you mean", yours is more concise. I could go either way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah… this is personal preference, I agree.
since most of the code is using ternaries rather than "truthy-switches" (whatever they're called), I'd roll with your solution for now.

resolved._parts.path = (basedir ? (basedir + '/') : '') + resolved._parts.path;
resolved.normalizePath();
}
Expand Down
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,16 @@
url: './relative/path?blubber=1#hash3',
base: '/path/to/file?some=query#hash',
result: '/path/to/relative/path?blubber=1#hash3'
}, {
name: 'path-relative path resolve 2',
url: 'tofile',
base: '/path/to/file',
result: '/path/to/tofile'
}, {
name: 'path-relative path-root resolve',
url: 'tofile',
base: '/file',
result: '/tofile'
}, {
name: 'path-relative parent path resolve',
url: '../relative/path?blubber=1#hash3',
Expand Down