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

UI - fix encoding for user-entered paths #6294

Merged
merged 19 commits into from
Mar 1, 2019
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add path encode helper using route-recognizer normalizer methods
  • Loading branch information
meirish committed Feb 27, 2019
commit 3f4120ec00d34bcbae772b453013b0602d4dcae2
14 changes: 14 additions & 0 deletions ui/app/utils/path-encoding-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import RouteRecognizer from 'route-recognizer';

const {
Normalizer: { normalizePath, encodePathSegment },
} = RouteRecognizer;

Choose a reason for hiding this comment

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

When I did this in Consul Land I wondered whether to use encodeURIComponent or this slightly customized version. Just wondering if I should change to use this RouteRecognizer one also?

Just been reading this:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent#Description

It mentions something similar to adhere to RFC 3986. I don't follow what impact following this/not following this would mean. Do you know what the ins and outs are? Are ! etc just reserved for future or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/tildeio/route-recognizer/blob/master/lib/route-recognizer/normalizer.ts#L20 has some good comments - I was thinking it'd be nice to have the same semantics as the router. I think for adapter use it's not strictly necessary, but decoded slashes still look nicer.


export function encodePath(path) {
return path
.split('/')
.map(encodePathSegment)
.join('/');
}

export { normalizePath, encodePathSegment };