Commit 1546c2ad authored by Phil Hughes's avatar Phil Hughes Committed by Stan Hu

Fixes Vue file list for paths with non-ascii characters

This also fixes the logs tree endpoint not returning any
commit data for a path with a non-ascii character

Closes https://gitlab.com/gitlab-org/gitlab/issues/207499
parent 0b14793d
<script> <script>
import { GlDropdown, GlDropdownDivider, GlDropdownHeader, GlDropdownItem } from '@gitlab/ui'; import { GlDropdown, GlDropdownDivider, GlDropdownHeader, GlDropdownItem } from '@gitlab/ui';
import { joinPaths } from '~/lib/utils/url_utility';
import { __ } from '../../locale'; import { __ } from '../../locale';
import Icon from '../../vue_shared/components/icon.vue'; import Icon from '../../vue_shared/components/icon.vue';
import getRefMixin from '../mixins/get_ref'; import getRefMixin from '../mixins/get_ref';
...@@ -102,12 +103,12 @@ export default { ...@@ -102,12 +103,12 @@ export default {
.filter(p => p !== '') .filter(p => p !== '')
.reduce( .reduce(
(acc, name, i) => { (acc, name, i) => {
const path = `${i > 0 ? acc[i].path : ''}/${name}`; const path = joinPaths(i > 0 ? acc[i].path : '', encodeURIComponent(name));
return acc.concat({ return acc.concat({
name, name,
path, path,
to: `/-/tree/${escape(this.ref)}${escape(path)}`, to: `/-/tree/${joinPaths(escape(this.ref), path)}`,
}); });
}, },
[ [
......
...@@ -91,7 +91,9 @@ export default { ...@@ -91,7 +91,9 @@ export default {
}, },
computed: { computed: {
routerLinkTo() { routerLinkTo() {
return this.isFolder ? { path: `/-/tree/${escape(this.ref)}/${escape(this.path)}` } : null; return this.isFolder
? { path: `/-/tree/${escape(this.ref)}/${encodeURIComponent(this.path)}` }
: null;
}, },
iconName() { iconName() {
return `fa-${getIconName(this.type, this.path)}`; return `fa-${getIconName(this.type, this.path)}`;
...@@ -141,6 +143,7 @@ export default { ...@@ -141,6 +143,7 @@ export default {
<i v-else :aria-label="type" role="img" :class="iconName" class="fa fa-fw"></i> <i v-else :aria-label="type" role="img" :class="iconName" class="fa fa-fw"></i>
<component <component
:is="linkComponent" :is="linkComponent"
ref="link"
:to="routerLinkTo" :to="routerLinkTo"
:href="url" :href="url"
class="str-truncated" class="str-truncated"
......
...@@ -27,7 +27,7 @@ export function fetchLogsTree(client, path, offset, resolver = null) { ...@@ -27,7 +27,7 @@ export function fetchLogsTree(client, path, offset, resolver = null) {
fetchpromise = axios fetchpromise = axios
.get( .get(
`${gon.relative_url_root}/${projectPath}/-/refs/${escape(ref)}/logs_tree/${escape( `${gon.relative_url_root}/${projectPath}/-/refs/${escape(ref)}/logs_tree/${encodeURIComponent(
path.replace(/^\//, ''), path.replace(/^\//, ''),
)}`, )}`,
{ {
......
---
title: Fixed repository browsing for folders with non-ascii characters
merge_request: 25877
author:
type: fixed
...@@ -69,7 +69,7 @@ module Gitlab ...@@ -69,7 +69,7 @@ module Gitlab
end end
def entry_path(entry) def entry_path(entry)
File.join(*[path, entry[:file_name]].compact) File.join(*[path, entry[:file_name]].compact).force_encoding(Encoding::ASCII_8BIT)
end end
def build_entry(entry) def build_entry(entry)
......
...@@ -41,7 +41,7 @@ describe('Repository breadcrumbs component', () => { ...@@ -41,7 +41,7 @@ describe('Repository breadcrumbs component', () => {
.findAll(RouterLinkStub) .findAll(RouterLinkStub)
.at(3) .at(3)
.props('to'), .props('to'),
).toEqual('/-/tree//app/assets/javascripts%23'); ).toEqual('/-/tree/app/assets/javascripts%23');
}); });
it('renders last link as active', () => { it('renders last link as active', () => {
......
...@@ -109,6 +109,26 @@ describe('Repository table row component', () => { ...@@ -109,6 +109,26 @@ describe('Repository table row component', () => {
}); });
}); });
it.each`
path
${'test#'}
${'Änderungen'}
`('renders link for $path', ({ path }) => {
factory({
id: '1',
sha: '123',
path,
type: 'tree',
currentPath: '/',
});
return vm.vm.$nextTick().then(() => {
expect(vm.find({ ref: 'link' }).props('to')).toEqual({
path: `/-/tree/master/${encodeURIComponent(path)}`,
});
});
});
it('pushes new route for directory with hash', () => { it('pushes new route for directory with hash', () => {
factory({ factory({
id: '1', id: '1',
......
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