-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Handle encoding and decoding of angular route url components #34300
Conversation
Pinging @elastic/kibana-platform |
src/legacy/ui/public/url/url.js
Outdated
$location.hash(match[5] || ''); | ||
|
||
return $location; | ||
}; |
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 awesome! Good job!
The reason Angular didn't fix this (they actually did but had to revert) was because too much of the ecosystem was relying on the broken behaviour. We should make sure that's not the case in Kibana.
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.
Thank you! Just a note: I walked through every usage of parameter encoding in Kibana I could find to see if there was any codec work around the URL and these were all I could find.
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.
I walked through every usage of parameter encoding in Kibana I could find to see if there was any codec work around the URL and these were all I could find.
Wow, that sounds painful 😁
I'll spin this up tomorrow, and let you know how APM fares.
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.
Hmm.. just tried it and it seems to break the url.
This url:
http://localhost:5601/app/apm#/opbeans-node/transactions/request/GET%20%2Fapi%2Fcustomers
Redirects to:
http://localhost:5601/app/apm#/opbeans-node/transactions/request/GET%20/api/customers
(Notice how the encoded forward slashes gets decoded)
src/legacy/ui/public/url/url.js
Outdated
* @param {String} url | ||
* @returns $location | ||
*/ | ||
$location.url = url => { |
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.
I added a breakpoint here, and it seems that url
has already been decoded at this point.
Going to http://localhost:5601/app/apm#/opbeans-node/transactions/request/GET%20%2Fapi%2Fcustomers, I get url="/opbeans-node/transactions/request/GET%20/api/customers"
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.
Thanks for testing! I'll take a look and get this fixed.
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.
Found it:
kibana/src/legacy/ui/public/chrome/directives/kbn_chrome.js
Lines 77 to 88 in 7198a1f
$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(); | |
} | |
}); |
Specifically:
const absUrlHash = url.parse($location.absUrl()).hash.slice(1); |
newUrl
is correct but absUrlHash
decoded the forward slashes.
@spalger you might find this interesting/infuriating :p
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.
Btw even if you don't have any APM data, you should be able to repro this issue by going to the APM app:
/app/apm#/any-service/transactions/request/GET%20%2Fapi%2Fcustomers
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.
Should these two "corrections" be merged into a single thing?
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.
@joshdover I'm not following?
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.
oh, whether stuff in ui/public/chrome/directives/kbn_chrome.js
and ui/public/url/url.js
should be merged? Yes, if possible, that sounds like a good improvement 👍
1b3b52f
to
a1ac4aa
Compare
@sqren would you mind testing this branch out again? I am using a forked version of angular that avoids the path codecs to test out here. |
This comment has been minimized.
This comment has been minimized.
@eliperelman Just tested this and works well. Didn't notice any decoding issues. |
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.
I just recall that this problem is not isolated to Angular but also affects nginx and golang. I'm currently looking into this and seeing if we can give good workarounds to users in these situations. But the best solution might be to leave the legacyEncodeURIComponent
in.
Examples of users seeing this problem with nginx:
a1ac4aa
to
8dc092d
Compare
This comment has been minimized.
This comment has been minimized.
a93c282
to
cf460a0
Compare
This comment has been minimized.
This comment has been minimized.
cf460a0
to
dd1c60b
Compare
This comment has been minimized.
This comment has been minimized.
dd1c60b
to
0e3537c
Compare
This comment has been minimized.
This comment has been minimized.
0e3537c
to
f0f6786
Compare
retest |
This comment has been minimized.
This comment has been minimized.
Sounds good 👍
Just to be clear: this problem affects anybody who has uri-encoded characters in the url and has an nginx or go proxy in front. It's not an APM specific problem unfortunately. |
💚 Build Succeeded |
💔 Build Failed |
@eliperelman I slapped the |
…lastic#34300)" (elastic#36226) This reverts commit ed97dc6.
…lastic#34300)" (elastic#36226) This reverts commit ed97dc6.
Summary
Handle encoding and decoding of Angular route URL components. This used to be handled automatically by Angular, but was reverted. This patch re-introduces this change and handles it in
KbnUrlProvider
.Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.This was checked for cross-browser compatibility, including a check against IE11Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n supportDocumentation was added for features that require explanation or tutorialsThis was checked for keyboard-only and screenreader accessibilityFor maintainers
Dev Docs
Handle encoding and decoding of Angular route URL components. This addition has since been reverted.