Skip to content
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

Merged
merged 4 commits into from
Apr 30, 2019

Conversation

eliperelman
Copy link
Contributor

@eliperelman eliperelman commented Apr 1, 2019

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 strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

Dev Docs

Handle encoding and decoding of Angular route URL components. This addition has since been reverted.

@eliperelman eliperelman added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Feature:New Platform v8.0.0 v7.2.0 labels Apr 1, 2019
@eliperelman eliperelman self-assigned this Apr 1, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform

@eliperelman eliperelman requested a review from a team as a code owner April 1, 2019 17:32
$location.hash(match[5] || '');

return $location;
};
Copy link
Member

@sorenlouv sorenlouv Apr 1, 2019

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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)

* @param {String} url
* @returns $location
*/
$location.url = url => {
Copy link
Member

@sorenlouv sorenlouv Apr 1, 2019

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"

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found it:

$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

Copy link
Member

@sorenlouv sorenlouv Apr 1, 2019

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

Copy link
Contributor

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?

Copy link
Member

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?

Copy link
Member

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 👍

@eliperelman
Copy link
Contributor Author

@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.

@elasticmachine

This comment has been minimized.

@sorenlouv
Copy link
Member

@eliperelman Just tested this and works well. Didn't notice any decoding issues.
Thanks for doing this!
How are you planning to get this in? Should we run your fork of Angular, or is there a way to apply your changes on top of vanilla angular?

@joshdover joshdover mentioned this pull request Apr 5, 2019
10 tasks
Copy link
Member

@sorenlouv sorenlouv left a 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:

@elasticmachine

This comment has been minimized.

@eliperelman eliperelman force-pushed the angular-route-codec branch 2 times, most recently from a93c282 to cf460a0 Compare April 10, 2019 18:55
@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@eliperelman
Copy link
Contributor Author

retest

@elasticmachine

This comment has been minimized.

@sorenlouv
Copy link
Member

sorenlouv commented Apr 23, 2019

I have revised the PR to only bring in the angular changes.

Sounds good 👍

I think that since it appears that only APM is needing to use these bandaids it is OK to keep them in since it solves a particular problem that doesn't seem to exist elsewhere.

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.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@eliperelman eliperelman requested a review from a team April 26, 2019 16:33
@eliperelman eliperelman merged commit ed97dc6 into elastic:master Apr 30, 2019
@epixa epixa added the release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. label May 7, 2019
@elasticmachine
Copy link
Contributor

💔 Build Failed

@epixa
Copy link
Contributor

epixa commented Jun 4, 2019

@eliperelman I slapped the reverted label on this PR. Feel free to remove if I misunderstood something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:New Platform release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. reverted Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.2.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants