open-consul/ui-v2/app/helpers
John Cowen 6ec6530e03
UI: [BUGFIX] Decode/encode urls (#5206)
In 858b05fc31 (diff-46ef88aa04507fb9b039344277531584)
we removed encoding values in pathnames as we thought they were
eventually being encoded by `ember`. It looks like this isn't the case.

Turns out sometimes they are encoded sometimes they aren't. It's complicated.
If at all possible refer to the PR https://github.com/hashicorp/consul/pull/5206.

It's related to the difference between `dynamic` routes and `wildcard` routes.

Partly related to this is a decision on whether we urlencode the slashes within service names or not. Whilst historically we haven't done this, we feel its a good time to change this behaviour, so we'll also be changing services to use dynamic routes instead of wildcard routes. So service links will then look like /ui/dc-1/services/application%2Fservice rather than /ui/dc-1/services/application/service

Here, we define our routes in a declarative format (for the moment at least JSON) outside of Router.map, and loop through this within Router.map to set all our routes using the standard this.route method. We essentially configure our Router from the outside. As this configuration is now done declaratively outside of Router.map we can also make this data available to href-to and paramsFor, allowing us to detect wildcard routes and therefore apply urlencoding/decoding.

Where I mention 'conditionally' below, this is detection is what is used for the decision.

We conditionally add url encoding to the `{{href-to}}` helper/addon. The
reasoning here is, if we are asking for a 'href/url' then whatever we
receive back should always be urlencoded. We've done this by reusing as much
code from the original `ember-href-to` addon as possible, after this
change every call to the `{{href-to}}` helper will be urlencoded.

As all links using `{{href-to}}` are now properly urlencoded. We also
need to decode them in the correct place 'on the other end', so..

We also override the default `Route.paramsFor` method to conditionally decode all
params before passing them to the `Route.model` hook.

Lastly (the revert), as we almost consistently use url params to
construct API calls, we make sure we re-encode any slugs that have been
passed in by the user/developer. The original API for the `createURL`
function was to allow you to pass values that didn't need encoding,
values that **did** need encoding, followed by query params (which again
require url encoding)

All in all this should make the entire ember app url encode/decode safe.
2019-01-23 13:46:59 +00:00
..
policy UI: New ACLs (#4789) 2018-10-19 08:45:05 -07:00
service UI: External Source markers (#4640) 2018-09-12 20:23:39 +01:00
token ui: Make empty Rules ('') take priority over a `Legacy: true` (#4899) 2018-11-06 18:08:10 +00:00
atob.js UI V2 (#4086) 2018-05-10 19:52:53 +01:00
css-var.js ui: Add AWS external-source icon (#5030) 2018-11-30 09:59:02 +00:00
default.js ui: Adds a `default` view helper for providing a default value (#4650) 2018-09-12 20:38:57 +01:00
difference.js UI: New ACLs (#4789) 2018-10-19 08:45:05 -07:00
env.js UI V2 (#4086) 2018-05-10 19:52:53 +01:00
format-number.js UI: Reduce in-development deprecations (also use toLocaleString) (#4677) 2018-10-01 13:42:42 +01:00
href-to.js UI: [BUGFIX] Decode/encode urls (#5206) 2019-01-23 13:46:59 +00:00
is-href.js UI V2 (#4086) 2018-05-10 19:52:53 +01:00
last.js ui: Some trivial test additions, support env var passing of port numbers (#4728) 2018-10-26 17:50:43 +01:00
left-trim.js Adds filtering to the KV listing page 2018-06-12 11:24:35 +01:00
right-trim.js Adds filtering to the KV listing page 2018-06-12 11:24:35 +01:00
slugify.js UI V2 (#4086) 2018-05-10 19:52:53 +01:00
split.js ui: Some trivial test additions, support env var passing of port numbers (#4728) 2018-10-26 17:50:43 +01:00