Commit 3ebd5793 authored by Phil Hughes's avatar Phil Hughes

Fix Apollo throwing error with specific path names

Also fixes the display of folders with special characters
parent ec46fc91
<script> <script>
import { escapeRegExp } from 'lodash';
import { GlBadge, GlLink, GlSkeletonLoading, GlTooltipDirective, GlLoadingIcon } from '@gitlab/ui'; import { GlBadge, GlLink, GlSkeletonLoading, GlTooltipDirective, GlLoadingIcon } from '@gitlab/ui';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import TimeagoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; import TimeagoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
...@@ -105,7 +106,7 @@ export default { ...@@ -105,7 +106,7 @@ export default {
return this.isFolder ? 'router-link' : 'a'; return this.isFolder ? 'router-link' : 'a';
}, },
fullPath() { fullPath() {
return this.path.replace(new RegExp(`^${this.currentPath}/`), ''); return this.path.replace(new RegExp(`^${escapeRegExp(this.currentPath)}/`), '');
}, },
shortSha() { shortSha() {
return this.sha.slice(0, 8); return this.sha.slice(0, 8);
......
...@@ -48,7 +48,7 @@ const defaultClient = createDefaultClient( ...@@ -48,7 +48,7 @@ const defaultClient = createDefaultClient(
case 'TreeEntry': case 'TreeEntry':
case 'Submodule': case 'Submodule':
case 'Blob': case 'Blob':
return `${obj.flatPath}-${obj.id}`; return `${escape(obj.flatPath)}-${obj.id}`;
default: default:
// If the type doesn't match any of the above we fallback // If the type doesn't match any of the above we fallback
// to using the default Apollo ID // to using the default Apollo ID
......
...@@ -48,3 +48,52 @@ exports[`Repository table row component renders table row 1`] = ` ...@@ -48,3 +48,52 @@ exports[`Repository table row component renders table row 1`] = `
</td> </td>
</tr> </tr>
`; `;
exports[`Repository table row component renders table row for path with special character 1`] = `
<tr
class="tree-item file_1"
>
<td
class="tree-item-file-name"
>
<i
aria-label="file"
class="fa fa-fw fa-file-text-o"
role="img"
/>
<a
class="str-truncated"
href="https://test.com"
>
test
</a>
<!---->
<!---->
<!---->
</td>
<td
class="d-none d-sm-table-cell tree-commit"
>
<gl-skeleton-loading-stub
class="h-auto"
lines="1"
/>
</td>
<td
class="tree-time-ago text-right"
>
<gl-skeleton-loading-stub
class="ml-auto h-auto w-50"
lines="1"
/>
</td>
</tr>
`;
...@@ -51,6 +51,20 @@ describe('Repository table row component', () => { ...@@ -51,6 +51,20 @@ describe('Repository table row component', () => {
}); });
}); });
it('renders table row for path with special character', () => {
factory({
id: '1',
sha: '123',
path: 'test$/test',
type: 'file',
currentPath: 'test$',
});
return vm.vm.$nextTick().then(() => {
expect(vm.element).toMatchSnapshot();
});
});
it.each` it.each`
type | component | componentName type | component | componentName
${'tree'} | ${RouterLinkStub} | ${'RouterLink'} ${'tree'} | ${RouterLinkStub} | ${'RouterLink'}
......
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