mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[chrome] strip # from hash before updating $location (#32732)
* add functional test to prove regression * [chrome] strip # from hash before updating $location * add opt-out level for disabling auto fix, disable in APM
This commit is contained in:
parent
97f8145fd5
commit
319921ebfc
5 changed files with 38 additions and 14 deletions
6
src/legacy/ui/public/chrome/api/angular.js
vendored
6
src/legacy/ui/public/chrome/api/angular.js
vendored
|
@ -34,6 +34,12 @@ const URL_LIMIT_WARN_WITHIN = 1000;
|
|||
export function initAngularApi(chrome, internals) {
|
||||
chrome.getFirstPathSegment = _.noop;
|
||||
|
||||
internals.disableAutoAngularUrlEncodingFix = false;
|
||||
chrome.disableAutoAngularUrlEncodingFix = () => {
|
||||
internals.disableAutoAngularUrlEncodingFix = true;
|
||||
return chrome;
|
||||
};
|
||||
|
||||
chrome.setupAngular = function () {
|
||||
const kibana = uiModules.get('kibana');
|
||||
|
||||
|
|
|
@ -74,19 +74,21 @@ export function kbnChromeProvider(chrome, internals) {
|
|||
}
|
||||
}
|
||||
|
||||
$rootScope.$on('$locationChangeStart', (e, newUrl) => {
|
||||
// This handler fixes issue #31238 where browser back navigation
|
||||
// fails due to angular 1.6 parsing url encoded params wrong.
|
||||
const absUrlHash = url.parse($location.absUrl()).hash;
|
||||
const decodedAbsUrlHash = decodeURIComponent(absUrlHash);
|
||||
const hash = url.parse(newUrl).hash;
|
||||
const decodedHash = decodeURIComponent(hash);
|
||||
if (absUrlHash !== hash && decodedHash === decodedAbsUrlHash) {
|
||||
// replace the urlencoded hash with the version that angular sees.
|
||||
$location.url(absUrlHash).replace();
|
||||
}
|
||||
if (!internals.disableAutoAngularUrlEncodingFix) {
|
||||
$rootScope.$on('$locationChangeStart', (e, newUrl) => {
|
||||
// This handler fixes issue #31238 where browser back navigation
|
||||
// fails due to angular 1.6 parsing url encoded params wrong.
|
||||
const absUrlHash = url.parse($location.absUrl()).hash.slice(1);
|
||||
const decodedAbsUrlHash = decodeURIComponent(absUrlHash);
|
||||
const hash = url.parse(newUrl).hash.slice(1);
|
||||
const decodedHash = decodeURIComponent(hash);
|
||||
if (absUrlHash !== hash && decodedHash === decodedAbsUrlHash) {
|
||||
// replace the urlencoded hash with the version that angular sees.
|
||||
$location.url(absUrlHash).replace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
$rootScope.$on('$routeChangeSuccess', onRouteChange);
|
||||
$rootScope.$on('$routeUpdate', onRouteChange);
|
||||
updateSubUrls(); // initialize sub urls
|
||||
|
|
1
src/legacy/ui/public/chrome/index.d.ts
vendored
1
src/legacy/ui/public/chrome/index.d.ts
vendored
|
@ -45,6 +45,7 @@ declare interface Chrome extends ChromeNavLinks {
|
|||
addApplicationClass(classNames: string | string[]): this;
|
||||
removeApplicationClass(classNames: string | string[]): this;
|
||||
getApplicationClasses(): string;
|
||||
disableAutoAngularUrlEncodingFix(): this;
|
||||
}
|
||||
|
||||
declare const chrome: Chrome;
|
||||
|
|
|
@ -22,16 +22,18 @@ import expect from 'expect.js';
|
|||
|
||||
export default function ({ getService, getPageObjects }) {
|
||||
const browser = getService('browser');
|
||||
const PageObjects = getPageObjects(['dashboard', 'common', 'home', 'timePicker']);
|
||||
const PageObjects = getPageObjects(['common', 'home', 'timePicker']);
|
||||
const appsMenu = getService('appsMenu');
|
||||
const kibanaServer = getService('kibanaServer');
|
||||
const esArchiver = getService('esArchiver');
|
||||
const retry = getService('retry');
|
||||
const fromTime = '2015-09-19 06:31:44.000';
|
||||
const toTime = '2015-09-23 18:31:44.000';
|
||||
|
||||
describe('Kibana browser back navigation should work', function describeIndexTests() {
|
||||
|
||||
before(async () => {
|
||||
await PageObjects.dashboard.initTests();
|
||||
await esArchiver.loadIfNeeded('makelogs');
|
||||
await kibanaServer.uiSettings.disableToastAutohide();
|
||||
await browser.refresh();
|
||||
});
|
||||
|
@ -69,6 +71,18 @@ export default function ({ getService, getPageObjects }) {
|
|||
currUrl = await browser.getCurrentUrl();
|
||||
expect(currUrl).to.be(homeUrl);
|
||||
});
|
||||
|
||||
it('encodes portions of the URL as necessary', async () => {
|
||||
await browser.get('http://localhost:5620/app/kibana#/home', false);
|
||||
await retry.waitFor('navigation to home app', async () => (
|
||||
(await browser.getCurrentUrl()) === 'http://localhost:5620/app/kibana#/home?_g=()'
|
||||
));
|
||||
|
||||
await browser.get('http://localhost:5620/app/kibana#/home?_g=()&a=b/c', false);
|
||||
await retry.waitFor('hash to be properly encoded', async () => (
|
||||
(await browser.getCurrentUrl()) === 'http://localhost:5620/app/kibana#/home?_g=()&a=b%2Fc'
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ type PromiseResolver = (value?: {} | PromiseLike<{}> | undefined) => void;
|
|||
|
||||
// @ts-ignore
|
||||
chrome.setRootTemplate(template);
|
||||
chrome.disableAutoAngularUrlEncodingFix();
|
||||
const store = configureStore();
|
||||
const checkForRoot = (resolve: PromiseResolver) => {
|
||||
const ready = !!document.getElementById(REACT_APP_ROOT_ID);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue