Commit 96ab15f2 authored by Paul Slaughter's avatar Paul Slaughter

Move escapeFileUrl to shared url_utility

**Why?**
This is no longer needed in just the IDE.
We also need it to make sure we properly
escape paths in the file finder.
parent 264efb4d
import { viewerInformationForPath } from '~/vue_shared/components/content_viewer/lib/viewer_utils';
import { decorateData, sortTree, escapeFileUrl } from '../stores/utils';
import { escapeFileUrl } from '~/lib/utils/url_utility';
import { decorateData, sortTree } from '../stores/utils';
export const splitParent = path => {
const idx = path.lastIndexOf('/');
......
import axios from '~/lib/utils/axios_utils';
import { joinPaths } from '~/lib/utils/url_utility';
import { escapeFileUrl } from '../stores/utils';
import { joinPaths, escapeFileUrl } from '~/lib/utils/url_utility';
import Api from '~/api';
export default {
......
import { joinPaths } from '~/lib/utils/url_utility';
import { joinPaths, escapeFileUrl } from '~/lib/utils/url_utility';
import { __ } from '~/locale';
import eventHub from '../../eventhub';
import service from '../../services';
import * as types from '../mutation_types';
import router from '../../ide_router';
import { escapeFileUrl, addFinalNewlineIfNeeded, setPageTitleForFile } from '../utils';
import { addFinalNewlineIfNeeded, setPageTitleForFile } from '../utils';
import { viewerTypes, stageKeys } from '../../constants';
export const closeFile = ({ commit, state, dispatch }, file) => {
......
import { commitActionTypes, FILE_VIEW_MODE_EDITOR } from '../constants';
import { escapeFileUrl } from '~/lib/utils/url_utility';
export const dataStructure = () => ({
id: '',
......@@ -217,8 +218,6 @@ export const mergeTrees = (fromTree, toTree) => {
return toTree;
};
export const escapeFileUrl = fileUrl => encodeURIComponent(fileUrl).replace(/%2F/g, '/');
export const replaceFileUrl = (url, oldPath, newPath) => {
// Add `/-/` so that we don't accidentally replace project path
const result = url.replace(`/-/${escapeFileUrl(oldPath)}`, `/-/${escapeFileUrl(newPath)}`);
......
......@@ -280,3 +280,5 @@ export const setUrlParams = (params, url = window.location.href, clearParams = f
return urlObj.toString();
};
export const escapeFileUrl = fileUrl => encodeURIComponent(fileUrl).replace(/%2F/g, '/');
import { viewerInformationForPath } from '~/vue_shared/components/content_viewer/lib/viewer_utils';
import { decorateFiles, splitParent } from '~/ide/lib/files';
import { decorateData, escapeFileUrl } from '~/ide/stores/utils';
import { decorateData } from '~/ide/stores/utils';
import { escapeFileUrl } from '~/lib/utils/url_utility';
const TEST_BRANCH_ID = 'lorem-ipsum';
const TEST_PROJECT_ID = 10;
......
......@@ -2,7 +2,7 @@ import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import services from '~/ide/services';
import Api from '~/api';
import { escapeFileUrl } from '~/ide/stores/utils';
import { escapeFileUrl } from '~/lib/utils/url_utility';
jest.mock('~/api');
......
......@@ -395,14 +395,6 @@ describe('Multi-file store utils', () => {
});
});
describe('escapeFileUrl', () => {
it('encodes URL excluding the slashes', () => {
expect(utils.escapeFileUrl('/foo-bar/file.md')).toBe('/foo-bar/file.md');
expect(utils.escapeFileUrl('foo bar/file.md')).toBe('foo%20bar/file.md');
expect(utils.escapeFileUrl('foo/bar/file.md')).toBe('foo/bar/file.md');
});
});
describe('swapInStateArray', () => {
let localState;
......
......@@ -322,6 +322,14 @@ describe('URL utility', () => {
expect(urlUtils.joinPaths(...paths)).toBe(expected);
});
});
describe('escapeFileUrl', () => {
it('encodes URL excluding the slashes', () => {
expect(urlUtils.escapeFileUrl('/foo-bar/file.md')).toBe('/foo-bar/file.md');
expect(urlUtils.escapeFileUrl('foo bar/file.md')).toBe('foo%20bar/file.md');
expect(urlUtils.escapeFileUrl('foo/bar/file.md')).toBe('foo/bar/file.md');
});
});
});
describe('setUrlParams', () => {
......
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