Commit 44582106 authored by Phil Hughes's avatar Phil Hughes

Escape branch name on backend

Instead of handling the escaping of the branch name on the frontend
we now get passed the escaped branch name from the backend

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/215917
parent 0138be44
...@@ -108,14 +108,14 @@ export default { ...@@ -108,14 +108,14 @@ export default {
return acc.concat({ return acc.concat({
name, name,
path, path,
to: `/-/tree/${joinPaths(escapeFileUrl(this.ref), path)}`, to: `/-/tree/${joinPaths(this.escapedRef, path)}`,
}); });
}, },
[ [
{ {
name: this.projectShortPath, name: this.projectShortPath,
path: '/', path: '/',
to: `/-/tree/${escapeFileUrl(this.ref)}/`, to: `/-/tree/${this.escapedRef}/`,
}, },
], ],
); );
......
...@@ -81,7 +81,7 @@ export default { ...@@ -81,7 +81,7 @@ export default {
<tbody> <tbody>
<parent-row <parent-row
v-show="showParentRow" v-show="showParentRow"
:commit-ref="ref" :commit-ref="escapedRef"
:path="path" :path="path"
:loading-path="loadingPath" :loading-path="loadingPath"
/> />
......
<script> <script>
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import { escapeFileUrl } from '~/lib/utils/url_utility';
export default { export default {
components: { components: {
...@@ -29,7 +28,7 @@ export default { ...@@ -29,7 +28,7 @@ export default {
return splitArray.map(p => encodeURIComponent(p)).join('/'); return splitArray.map(p => encodeURIComponent(p)).join('/');
}, },
parentRoute() { parentRoute() {
return { path: `/-/tree/${escapeFileUrl(this.commitRef)}/${this.parentPath}` }; return { path: `/-/tree/${this.commitRef}/${this.parentPath}` };
}, },
}, },
methods: { methods: {
......
...@@ -99,7 +99,7 @@ export default { ...@@ -99,7 +99,7 @@ export default {
computed: { computed: {
routerLinkTo() { routerLinkTo() {
return this.isFolder return this.isFolder
? { path: `/-/tree/${escapeFileUrl(this.ref)}/${escapeFileUrl(this.path)}` } ? { path: `/-/tree/${this.escapedRef}/${escapeFileUrl(this.path)}` }
: null; : null;
}, },
isFolder() { isFolder() {
......
...@@ -15,14 +15,15 @@ import { __ } from '../locale'; ...@@ -15,14 +15,15 @@ import { __ } from '../locale';
export default function setupVueRepositoryList() { export default function setupVueRepositoryList() {
const el = document.getElementById('js-tree-list'); const el = document.getElementById('js-tree-list');
const { dataset } = el; const { dataset } = el;
const { projectPath, projectShortPath, ref, fullName } = dataset; const { projectPath, projectShortPath, ref, escapedRef, fullName } = dataset;
const router = createRouter(projectPath, ref); const router = createRouter(projectPath, escapedRef);
apolloProvider.clients.defaultClient.cache.writeData({ apolloProvider.clients.defaultClient.cache.writeData({
data: { data: {
projectPath, projectPath,
projectShortPath, projectShortPath,
ref, ref,
escapedRef,
vueFileListLfsBadge: gon.features?.vueFileListLfsBadge || false, vueFileListLfsBadge: gon.features?.vueFileListLfsBadge || false,
commits: [], commits: [],
}, },
......
...@@ -23,13 +23,13 @@ export function fetchLogsTree(client, path, offset, resolver = null) { ...@@ -23,13 +23,13 @@ export function fetchLogsTree(client, path, offset, resolver = null) {
if (fetchpromise) return fetchpromise; if (fetchpromise) return fetchpromise;
const { projectPath } = client.readQuery({ query: getProjectPath }); const { projectPath } = client.readQuery({ query: getProjectPath });
const { ref } = client.readQuery({ query: getRef }); const { escapedRef } = client.readQuery({ query: getRef });
fetchpromise = axios fetchpromise = axios
.get( .get(
`${gon.relative_url_root}/${projectPath}/-/refs/${encodeURIComponent( `${gon.relative_url_root}/${projectPath}/-/refs/${escapedRef}/logs_tree/${encodeURIComponent(
ref, path.replace(/^\//, ''),
)}/logs_tree/${encodeURIComponent(path.replace(/^\//, ''))}`, )}`,
{ {
params: { format: 'json', offset }, params: { format: 'json', offset },
}, },
......
...@@ -4,11 +4,19 @@ export default { ...@@ -4,11 +4,19 @@ export default {
apollo: { apollo: {
ref: { ref: {
query: getRef, query: getRef,
manual: true,
result({ data, loading }) {
if (!loading) {
this.ref = data.ref;
this.escapedRef = data.escapedRef;
}
},
}, },
}, },
data() { data() {
return { return {
ref: '', ref: '',
escapedRef: '',
}; };
}, },
}; };
query getRef { query getRef {
ref @client ref @client
escapedRef @client
} }
...@@ -12,7 +12,7 @@ export default function createRouter(base, baseRef) { ...@@ -12,7 +12,7 @@ export default function createRouter(base, baseRef) {
base: joinPaths(gon.relative_url_root || '', base), base: joinPaths(gon.relative_url_root || '', base),
routes: [ routes: [
{ {
path: `(/-)?/tree/(${encodeURIComponent(baseRef).replace(/%2F/g, '/')}|${baseRef})/:path*`, path: `(/-)?/tree/${baseRef}/:path*`,
name: 'treePath', name: 'treePath',
component: TreePage, component: TreePage,
props: route => ({ props: route => ({
......
...@@ -194,6 +194,7 @@ module TreeHelper ...@@ -194,6 +194,7 @@ module TreeHelper
project_path: project.full_path, project_path: project.full_path,
project_short_path: project.path, project_short_path: project.path,
ref: ref, ref: ref,
escaped_ref: ActionDispatch::Journey::Router::Utils.escape_path(ref),
full_name: project.name_with_namespace full_name: project.name_with_namespace
} }
end end
......
---
title: Fixes branch name not getting escaped correctly on frontend
merge_request:
author:
type: fixed
...@@ -26,7 +26,7 @@ function factory(propsData = {}) { ...@@ -26,7 +26,7 @@ function factory(propsData = {}) {
}, },
}); });
vm.setData({ ref: 'master' }); vm.setData({ escapedRef: 'master' });
} }
describe('Repository table row component', () => { describe('Repository table row component', () => {
......
...@@ -53,7 +53,7 @@ describe('fetchLogsTree', () => { ...@@ -53,7 +53,7 @@ describe('fetchLogsTree', () => {
client = { client = {
readQuery: () => ({ readQuery: () => ({
projectPath: 'gitlab-org/gitlab-foss', projectPath: 'gitlab-org/gitlab-foss',
ref: 'master', escapedRef: 'master',
commits: [], commits: [],
}), }),
writeQuery: jest.fn(), writeQuery: jest.fn(),
......
...@@ -4,13 +4,12 @@ import createRouter from '~/repository/router'; ...@@ -4,13 +4,12 @@ import createRouter from '~/repository/router';
describe('Repository router spec', () => { describe('Repository router spec', () => {
it.each` it.each`
path | branch | component | componentName path | branch | component | componentName
${'/'} | ${'master'} | ${IndexPage} | ${'IndexPage'} ${'/'} | ${'master'} | ${IndexPage} | ${'IndexPage'}
${'/tree/master'} | ${'master'} | ${TreePage} | ${'TreePage'} ${'/tree/master'} | ${'master'} | ${TreePage} | ${'TreePage'}
${'/-/tree/master'} | ${'master'} | ${TreePage} | ${'TreePage'} ${'/-/tree/master'} | ${'master'} | ${TreePage} | ${'TreePage'}
${'/-/tree/master/app/assets'} | ${'master'} | ${TreePage} | ${'TreePage'} ${'/-/tree/master/app/assets'} | ${'master'} | ${TreePage} | ${'TreePage'}
${'/-/tree/feature/test-%23/app/assets'} | ${'feature/test-#'} | ${TreePage} | ${'TreePage'} ${'/-/tree/123/app/assets'} | ${'master'} | ${null} | ${'null'}
${'/-/tree/123/app/assets'} | ${'master'} | ${null} | ${'null'}
`('sets component as $componentName for path "$path"', ({ path, component, branch }) => { `('sets component as $componentName for path "$path"', ({ path, component, branch }) => {
const router = createRouter('', branch); const router = createRouter('', branch);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment