Skip to content

Commit

Permalink
Merge pull request #13781 from wagenet/fix-none-root-url
Browse files Browse the repository at this point in the history
[BUGFIX release] Fix NoneLocation#getURL
  • Loading branch information
rwjblue authored Jul 6, 2016
2 parents f54a209 + fe473a2 commit 7d52c53
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
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');
});

0 comments on commit 7d52c53

Please sign in to comment.