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

[BUGFIX release] Fix NoneLocation#getURL #13781

Merged
merged 1 commit into from
Jul 6, 2016
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
4 changes: 2 additions & 2 deletions packages/ember-routing/lib/location/history_location.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export default EmberObject.extend({

// remove baseURL and rootURL from start of path
var url = path
.replace(new RegExp('^' + baseURL), '')
.replace(new RegExp('^' + rootURL), '');
.replace(new RegExp('^' + baseURL + '(?=/|$)'), '')
.replace(new RegExp('^' + rootURL + '(?=/|$)'), '');

var search = location.search || '';
url += search;
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-routing/lib/location/none_location.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default EmberObject.extend({
rootURL = rootURL.replace(/\/$/, '');

// remove rootURL from url
return path.replace(new RegExp('^' + rootURL), '');
return path.replace(new RegExp('^' + rootURL + '(?=/|$)'), '');
},

/**
Expand Down
32 changes: 32 additions & 0 deletions packages/ember-routing/tests/location/history_location_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,22 @@ QUnit.test('HistoryLocation.getURL() returns the current url, does not remove ro
equal(location.getURL(), '/foo/bar/baz');
});

QUnit.test('HistoryLocation.getURL() will not remove the rootURL when only a partial match', function() {
expect(1);

HistoryTestLocation.reopen({
init() {
this._super(...arguments);
set(this, 'location', mockBrowserLocation('/bars/baz'));
set(this, 'rootURL', '/bar/');
}
});

createLocation();

equal(location.getURL(), '/bars/baz');
});

QUnit.test('HistoryLocation.getURL() returns the current url, does not remove baseURL if its not at start of url', function() {
expect(1);

Expand All @@ -206,6 +222,22 @@ QUnit.test('HistoryLocation.getURL() returns the current url, does not remove ba
equal(location.getURL(), '/foo/bar/baz');
});

QUnit.test('HistoryLocation.getURL() will not remove the baseURL when only a partial match', function() {
expect(1);

HistoryTestLocation.reopen({
init() {
this._super(...arguments);
set(this, 'location', mockBrowserLocation('/bars/baz'));
set(this, 'baseURL', '/bar/');
}
});

createLocation();

equal(location.getURL(), '/bars/baz');
});

QUnit.test('HistoryLocation.getURL() includes location.search', function() {
expect(1);

Expand Down
18 changes: 17 additions & 1 deletion packages/ember-routing/tests/location/none_location_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ QUnit.test('NoneLocation.getURL() returns the current path minus rootURL', funct
equal(location.getURL(), '/bar');
});

QUnit.test('NonoLocation.getURL() will remove the rootURL only from the beginning of a url', function() {
QUnit.test('NoneLocation.getURL() will remove the rootURL only from the beginning of a url', function() {
expect(1);

NoneTestLocation.reopen({
Expand All @@ -67,3 +67,19 @@ QUnit.test('NonoLocation.getURL() will remove the rootURL only from the beginnin

equal(location.getURL(), '/foo/bar/baz');
});

QUnit.test('NoneLocation.getURL() will not remove the rootURL when only a partial match', function() {
expect(1);

NoneTestLocation.reopen({
init() {
this._super(...arguments);
set(this, 'rootURL', '/bar/');
set(this, 'path', '/bars/baz');
}
});

createLocation();

equal(location.getURL(), '/bars/baz');
});