Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit fe518dc

Browse files
cosmosgeniusalexlafroscia
authored andcommitted
fix: skip instead of returning url when namespace is present in url
1 parent 975724d commit fe518dc

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

addon/mixins/ajax-request.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -482,18 +482,18 @@ export default Mixin.create({
482482

483483
let namespace = options.namespace || get(this, 'namespace');
484484
if (namespace) {
485-
// If the URL has already been constructed (presumably, by Ember Data), then we should just leave it alone
486-
const hasNamespaceRegex = new RegExp(`^(/)?${stripSlashes(namespace)}/`);
487-
if (hasNamespaceRegex.test(url)) {
488-
return url;
489-
}
490485
// If host is given then we need to strip leading slash too( as it will be added through join)
491486
if (host) {
492487
namespace = stripSlashes(namespace);
493488
} else if (endsWithSlash(namespace)) {
494489
namespace = removeTrailingSlash(namespace);
495490
}
496-
urlParts.push(namespace);
491+
492+
// If the URL has already been constructed (presumably, by Ember Data), then we should just leave it alone
493+
const hasNamespaceRegex = new RegExp(`^(/)?${stripSlashes(namespace)}/`);
494+
if (!hasNamespaceRegex.test(url)) {
495+
urlParts.push(namespace);
496+
}
497497
}
498498

499499
// *Only* remove a leading slash when there is host or namespace -- we need to maintain a trailing slash for

tests/unit/mixins/ajax-request-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ describe('Unit | Mixin | ajax request', function() {
227227
);
228228
});
229229

230+
it('is set on the url containing namespace', function() {
231+
const RequestWithHostAndNamespace = AjaxRequest.extend({
232+
host: 'https://discuss.emberjs.com',
233+
namespace: '/api/v1'
234+
});
235+
const service = new RequestWithHostAndNamespace();
236+
const url = '/api/v1/users/me';
237+
const ajaxoptions = service.options(url);
238+
239+
expect(ajaxoptions.url).to.equal(
240+
'https://discuss.emberjs.com/api/v1/users/me'
241+
);
242+
});
243+
230244
it('is set with the host address as `//` and url not starting with `/`', function() {
231245
const RequestWithHostAndNamespace = AjaxRequest.extend({
232246
host: '//'

0 commit comments

Comments
 (0)