fix short url in spaces (#58313) (#58443)

This commit is contained in:
Joe Reuter 2020-02-25 14:52:45 +01:00 committed by GitHub
parent f68147aada
commit 2294748149
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,6 +22,7 @@ import { schema } from '@kbn/config-schema';
import { shortUrlAssertValid } from './lib/short_url_assert_valid';
import { ShortUrlLookupService } from './lib/short_url_lookup';
import { modifyUrl } from '../../../../core/utils';
export const createGotoRoute = ({
router,
@ -48,9 +49,16 @@ export const createGotoRoute = ({
const uiSettings = context.core.uiSettings.client;
const stateStoreInSessionStorage = await uiSettings.get('state:storeInSessionStorage');
if (!stateStoreInSessionStorage) {
const basePath = http.basePath.get(request);
const prependedUrl = modifyUrl(url, parts => {
if (!parts.hostname && parts.pathname && parts.pathname.startsWith('/')) {
parts.pathname = `${basePath}${parts.pathname}`;
}
});
return response.redirected({
headers: {
location: http.basePath.prepend(url),
location: prependedUrl,
},
});
}