summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2019-04-24 22:50:55 +0000
committerFatih Acet <acetfatih@gmail.com>2019-04-24 22:50:55 +0000
commit045191628f8aa5a21c985776d6daf62a82da4161 (patch)
tree587354a320208e5ba5f78776e685e2215386e570
parent66ff5f3dc6c19ea382192897395acfbd4adbd0c2 (diff)
parent4abd43609795e1cc0652396b6a00bc38ed237371 (diff)
downloadgitlab-ce-045191628f8aa5a21c985776d6daf62a82da4161.tar.gz
Merge branch 'fix-api-ide-relative-url-root' into 'master'
Fix API and IDE path with `/` relative_url_root See merge request gitlab-org/gitlab-ce!27635
-rw-r--r--app/assets/javascripts/api.js7
-rw-r--r--app/assets/javascripts/ide/ide_router.js10
-rw-r--r--app/assets/javascripts/lib/utils/url_utility.js2
-rw-r--r--changelogs/unreleased/fix-api-ide-relative-url-root.yml5
-rw-r--r--spec/javascripts/api_spec.js14
5 files changed, 27 insertions, 11 deletions
diff --git a/app/assets/javascripts/api.js b/app/assets/javascripts/api.js
index 8754c253881..e583a8affd4 100644
--- a/app/assets/javascripts/api.js
+++ b/app/assets/javascripts/api.js
@@ -1,6 +1,7 @@
import $ from 'jquery';
import _ from 'underscore';
import axios from './lib/utils/axios_utils';
+import { joinPaths } from './lib/utils/url_utility';
const Api = {
groupsPath: '/api/:version/groups.json',
@@ -339,11 +340,7 @@ const Api = {
},
buildUrl(url) {
- let urlRoot = '';
- if (gon.relative_url_root != null) {
- urlRoot = gon.relative_url_root;
- }
- return urlRoot + url.replace(':version', gon.api_version);
+ return joinPaths(gon.relative_url_root || '', url.replace(':version', gon.api_version));
},
};
diff --git a/app/assets/javascripts/ide/ide_router.js b/app/assets/javascripts/ide/ide_router.js
index 229ef168926..518a9cf7a0f 100644
--- a/app/assets/javascripts/ide/ide_router.js
+++ b/app/assets/javascripts/ide/ide_router.js
@@ -1,6 +1,6 @@
import Vue from 'vue';
import VueRouter from 'vue-router';
-import { join as joinPath } from 'path';
+import { joinPaths } from '~/lib/utils/url_utility';
import flash from '~/flash';
import store from './stores';
@@ -34,7 +34,7 @@ const EmptyRouterComponent = {
const router = new VueRouter({
mode: 'history',
- base: `${gon.relative_url_root}/-/ide/`,
+ base: joinPaths(gon.relative_url_root || '', '/-/ide/'),
routes: [
{
path: '/project/:namespace+/:project',
@@ -46,11 +46,11 @@ const router = new VueRouter({
},
{
path: ':targetmode(edit|tree|blob)/:branchid+/',
- redirect: to => joinPath(to.path, '/-/'),
+ redirect: to => joinPaths(to.path, '/-/'),
},
{
path: ':targetmode(edit|tree|blob)',
- redirect: to => joinPath(to.path, '/master/-/'),
+ redirect: to => joinPaths(to.path, '/master/-/'),
},
{
path: 'merge_requests/:mrid',
@@ -58,7 +58,7 @@ const router = new VueRouter({
},
{
path: '',
- redirect: to => joinPath(to.path, '/edit/master/-/'),
+ redirect: to => joinPaths(to.path, '/edit/master/-/'),
},
],
},
diff --git a/app/assets/javascripts/lib/utils/url_utility.js b/app/assets/javascripts/lib/utils/url_utility.js
index 4ba84589705..bdfd06fc250 100644
--- a/app/assets/javascripts/lib/utils/url_utility.js
+++ b/app/assets/javascripts/lib/utils/url_utility.js
@@ -120,3 +120,5 @@ export function webIDEUrl(route = undefined) {
}
return returnUrl;
}
+
+export { join as joinPaths } from 'path';
diff --git a/changelogs/unreleased/fix-api-ide-relative-url-root.yml b/changelogs/unreleased/fix-api-ide-relative-url-root.yml
new file mode 100644
index 00000000000..8c058645f3e
--- /dev/null
+++ b/changelogs/unreleased/fix-api-ide-relative-url-root.yml
@@ -0,0 +1,5 @@
+---
+title: Fix FE API and IDE handling of '/' relative_url_root
+merge_request: 27635
+author:
+type: fixed
diff --git a/spec/javascripts/api_spec.js b/spec/javascripts/api_spec.js
index e537e0e8afc..494b3b934a8 100644
--- a/spec/javascripts/api_spec.js
+++ b/spec/javascripts/api_spec.js
@@ -4,7 +4,7 @@ import Api from '~/api';
describe('Api', () => {
const dummyApiVersion = 'v3000';
- const dummyUrlRoot = 'http://host.invalid';
+ const dummyUrlRoot = '/gitlab';
const dummyGon = {
api_version: dummyApiVersion,
relative_url_root: dummyUrlRoot,
@@ -32,6 +32,18 @@ describe('Api', () => {
expect(builtUrl).toEqual(expectedOutput);
});
+
+ [null, '', '/'].forEach(root => {
+ it(`works when relative_url_root is ${root}`, () => {
+ window.gon.relative_url_root = root;
+ const input = '/api/:version/foo/bar';
+ const expectedOutput = `/api/${dummyApiVersion}/foo/bar`;
+
+ const builtUrl = Api.buildUrl(input);
+
+ expect(builtUrl).toEqual(expectedOutput);
+ });
+ });
});
describe('group', () => {