-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Drilldowns] Simpler url parsing in sub url hooks #61245
Merged
Dosant
merged 7 commits into
elastic:master
from
Dosant:dev/simpler-url-parsing-in-sub-url-hooks
Mar 31, 2020
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2dd8148
Simpler url parsing in sub url hooks
Dosant 3fa4daa
Merge branch 'master' into dev/simpler-url-parsing-in-sub-url-hooks
elasticmachine a80ae9e
Merge branch 'master' of github.com:elastic/kibana into dev/simpler-u…
Dosant 8d1e568
review improvements
Dosant e373d73
Merge branch 'dev/simpler-url-parsing-in-sub-url-hooks' of github.com…
Dosant 7ab4ecd
Merge branch 'master' into dev/simpler-url-parsing-in-sub-url-hooks
elasticmachine 89a982f
Merge branch 'master' into dev/simpler-url-parsing-in-sub-url-hooks
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/legacy/ui/public/chrome/api/sub_url_hooks_utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { areHashesDifferentButDecodedHashesEquals } from './sub_url_hooks_utils'; | ||
|
||
test('false for different hashes', () => { | ||
const url1 = `https://localhost/kibana/#/dashboard/id`; | ||
const url2 = `https://localhost/kibana/#/dashboard/DIFFERENT`; | ||
expect(areHashesDifferentButDecodedHashesEquals(url1, url2)).toBeFalsy(); | ||
}); | ||
|
||
test('false for same hashes', () => { | ||
const hash = `/dashboard/id?_a=(filters:!(),query:(language:kuery,query:''))&_g=(filters:!(),time:(from:now-120m,to:now))`; | ||
const url1 = `https://localhost/kibana/#/${hash}`; | ||
expect(areHashesDifferentButDecodedHashesEquals(url1, url1)).toBeFalsy(); | ||
}); | ||
|
||
test('true for same hashes, but one is encoded', () => { | ||
const hash = `/dashboard/id?_a=(filters:!(),query:(language:kuery,query:''))&_g=(filters:!(),time:(from:now-120m,to:now))`; | ||
const url1 = `https://localhost/kibana/#/${hash}`; | ||
const url2 = `https://localhost/kibana/#/${encodeURIComponent(hash)}`; | ||
expect(areHashesDifferentButDecodedHashesEquals(url1, url2)).toBeTruthy(); | ||
}); | ||
|
||
/** | ||
* This edge case occurs when trying to navigate within kibana app using core's `navigateToApp` api | ||
* and there is reserved characters in hash (see: query:'' part) | ||
* For example: | ||
* ```ts | ||
* navigateToApp('kibana', { | ||
* path: '#/dashboard/f8bc19f0-6918-11ea-9258-a74c2ded064d?_a=(filters:!(),query:(language:kuery,query:''))&_g=(filters:!(),time:(from:now-120m,to:now))' | ||
* }) | ||
* ``` | ||
* Core internally is using url.parse which parses ' -> %27 and performs the navigation | ||
* Then angular decodes it back and causes redundant history record if not the fix which is covered by the test below | ||
*/ | ||
test("true for same hashes, but one has reserved character (') encoded", () => { | ||
const hash = `/dashboard/id?_a=(filters:!(),query:(language:kuery,query:''))&_g=(filters:!(),time:(from:now-120m,to:now))`; | ||
const url1 = `https://localhost/kibana/#/${hash}`; | ||
const url2 = `https://localhost/kibana/#/${hash.replace(/\'/g, '%27')}`; | ||
expect(areHashesDifferentButDecodedHashesEquals(url1, url2)).toBeTruthy(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export function areHashesDifferentButDecodedHashesEquals(urlA: string, urlB: string): boolean { | ||
const getHash = (url: string) => url.split('#')[1] ?? ''; | ||
const hashA = getHash(urlA); | ||
const decodedHashA = decodeURIComponent(hashA); | ||
|
||
const hashB = getHash(urlB); | ||
const decodedHashB = decodeURIComponent(hashB); | ||
|
||
return hashA !== hashB && decodedHashA === decodedHashB; | ||
Dosant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the change in a nutshell. instead of using
url.parse(url).hash
use this simpler method.The problem with url.parse that it encodes
'
->%27
.This test would fail with original functionality: https://github.com/elastic/kibana/pull/61245/files#diff-58b12ddd89613d7380892977f494f217R47