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

Add support for the file scheme to joinUrls. #5989

Merged
merged 3 commits into from
Nov 28, 2017
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 CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Change Log
### 1.40 - 2017-12-01

* Added ability to support touch event in Imagery Layers Split demo application. [#5948](https://github.com/AnalyticalGraphicsInc/cesium/pull/5948)
* Added `file:` scheme compatibility to `joinUrls`. [#5989](https://github.com/AnalyticalGraphicsInc/cesium/pull/5989)
* Fixed `Invalid asm.js: Invalid member of stdlib` console error by recompiling crunch.js with latest emscripten toolchain. [#5847](https://github.com/AnalyticalGraphicsInc/cesium/issues/5847)

### 1.39 - 2017-11-01
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/joinUrls.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ define([
url += '//' + baseUri.authority;

if (baseUri.path !== '' && baseUri.path !== '/') {
// The next line ensures that url (including a non-blank authority) ends with a slash.
url = url.replace(/\/?$/, '/');
baseUri.path = baseUri.path.replace(/^\/?/g, '');

// If authority is empty, add a third slash. This is primarily for the file scheme,
// where a blank authority indicates a file on localhost (as opposed to a network share).
if (baseUri.authority === '') {
url += '/';
}
}
}

Expand Down
73 changes: 65 additions & 8 deletions Specs/Core/joinUrlsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ defineSuite([

var qualifiedUrl = "http://www.url.com";
var qualifiedUrlWithQueryString = "http://www.url.com" + "?" + queryString;
var qualifiedUrlWithPath = "http://www.url.com/some/path";
var qualifiedUrlWithPath = "http://www.url.com/some/qualified/path";

// Local files require three slashes on the front, to leave the hostname blank.
// Windows is leanient so long as a drive letter is present. Other systems are not.
var localFileUrlWithPath = "file:///mnt/local/path";
var driveUrlWithPath = "file:///c:/some/drive/path";
// Files can be read from network shares with only two slashes on the front.
var networkUrlWithPath = "file://networkShareHostname/some/remote/path";

var absolutePath = "/some/path";
var absolutePathWithQueryString = absolutePath + "?" + queryString;
Expand Down Expand Up @@ -56,7 +63,7 @@ defineSuite([
});

it('appends relative path correctly to qualified url', function() {
var result = joinUrls(qualifiedUrl, absolutePath);
var result = joinUrls(qualifiedUrl, relativePath);
expect(result).toEqual(expectedQualifiedUrl);
});

Expand Down Expand Up @@ -95,14 +102,9 @@ defineSuite([
expect(result).toEqual(qualifiedUrl);
});

it('appends qualfied url correctly to qualified url with path', function() {
var result = joinUrls(qualifiedUrl, qualifiedUrlWithPath);
expect(result).toEqual(expectedQualifiedUrl);
});

it('appends qualfied url with path correctly to qualified url', function() {
var result = joinUrls(qualifiedUrl, qualifiedUrlWithPath);
expect(result).toEqual(expectedQualifiedUrl);
expect(result).toEqual(qualifiedUrlWithPath);
});

it('appends qualfied url with path correctly to qualified url with path', function() {
Expand Down Expand Up @@ -168,4 +170,59 @@ defineSuite([
result = joinUrls(absolutePath, dataUri);
expect(result).toEqual(dataUri);
});

// File scheme tests
//
// NOTE: Following example set by 'appends absolute path correctly to qualified url with path',
// the so-called 'absolutePath' is expected to simply append to the existing path, not reset it.

it('appends absolute path correctly to local file with path', function() {
var result = joinUrls(localFileUrlWithPath, absolutePath);
expect(result).toEqual(localFileUrlWithPath + absolutePath);
});

it('appends relative path correctly to local file with path', function() {
var result = joinUrls(localFileUrlWithPath, relativePath);
expect(result).toEqual(localFileUrlWithPath + absolutePath);
});

it('appends absolute path correctly to drive letter with path', function() {
var result = joinUrls(driveUrlWithPath, absolutePath);
expect(result).toEqual(driveUrlWithPath + absolutePath);
});

it('appends relative path correctly to drive letter with path', function() {
var result = joinUrls(driveUrlWithPath, relativePath);
expect(result).toEqual(driveUrlWithPath + absolutePath);
});

it('appends absolute path correctly to network share with path', function() {
var result = joinUrls(networkUrlWithPath, absolutePath);
expect(result).toEqual(networkUrlWithPath + absolutePath);
});

it('appends relative path correctly to network share with path', function() {
var result = joinUrls(networkUrlWithPath, relativePath);
expect(result).toEqual(networkUrlWithPath + absolutePath);
});

it('works when the file scheme appears in the second path', function() {
var result = joinUrls(driveUrlWithPath, localFileUrlWithPath);
expect(result).toEqual(localFileUrlWithPath);
});

it('works when a drive letter appears in the second path', function() {
var result = joinUrls(localFileUrlWithPath, driveUrlWithPath);
expect(result).toEqual(driveUrlWithPath);
});

it('works when the first is a network file and the second is a local file', function() {
var result = joinUrls(networkUrlWithPath, localFileUrlWithPath);
expect(result).toEqual(localFileUrlWithPath);
});

it('works when the first is a local file and the second is a network file', function() {
var result = joinUrls(localFileUrlWithPath, networkUrlWithPath);
expect(result).toEqual(networkUrlWithPath);
});
});