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

uri_string path-noscheme handling issue #5665

Open
u3s opened this issue Jan 31, 2022 · 1 comment
Open

uri_string path-noscheme handling issue #5665

u3s opened this issue Jan 31, 2022 · 1 comment
Assignees
Labels

Comments

@u3s
Copy link
Contributor

u3s commented Jan 31, 2022

Describe the bug
uri_string:recompose does not handle path-noscheme case (relative-path reference in RFC) properly (at least not according to RFC3986)

To Reproduce

uri_string:recompose(#{path => "fo:o/b:ar"}).
"fo:o/b:ar"  // should have been: "fo%3Ao/b:ar"

Expected behavior

uri_string:recompose(#{path => "fo:o/b:ar"}).
"fo%3Ao/b:ar"

1st segment of a path-noscheme should be segment-nz-nc, meaning ':' is not allowed in it and should be percent-encoded

@u3s u3s added team:PS Assigned to OTP team PS bug Issue is reported as a bug labels Jan 31, 2022
@u3s
Copy link
Contributor Author

u3s commented Feb 21, 2022

After checking RFC3986 4.2 Relative Reference, I think initial proposal might
not be optimal.

RFC suggests that relative-path reference should be preceded with a
dot-segment(./) if its 1st segment contains a colon - this is visualized below
with SOLUTION B pseudo code.

Main advantage I see is that adding a dot-segment
is neutral and not visible after reference is resolved.

Additionally, with B, user still has the possibility of expressing : with and without
percent encoding used in 1st segment.

%% TODAY #{path => "fo:o/b:ar"} is recomposed as #{scheme => "fo", path => "o/b:ar"}
1> uri_string:recompose(#{path => "fo:o/b:ar"}).
"fo:o/b:ar"
2> uri_string:recompose(#{scheme => "fo", path => "o/b:ar"}).
"fo:o/b:ar"
3> uri_string:resolve(uri_string:recompose(#{path => "fo:o/b:ar"}), "http:/localhost/a/b/c").
"fo:o/b:ar"

%% SOLUTION A: PERCENT_ENCODING ':' (initial idea)
4> uri_string:recompose(#{path => "fo:o/b:ar"}).
"fo%3Ao/b:ar"
5> uri_string:resolve(uri_string:recompose(#{path => "fo:o/b:ar"}), "http:/localhost/a/b/c").
"http://localhost/a/b/fo%3Ao/b:ar"
6> uri_string:resolve(uri_string:recompose(#{path => "fo%3Ao/b:ar"}), "http:/localhost/a/b/c").
"http://localhost/a/b/fo%3Ao/b:ar"

%% SOLUTION B: PREFIX WITH DOT-SEGMENT
7> uri_string:recompose(#{path => "fo:o/b:ar"}).
"./fo:o/b:ar"
8> uri_string:resolve(uri_string:recompose(#{path => "fo:o/b:ar"}), "http:/localhost/a/b/c").
"http://localhost/a/b/fo:o/b:ar"
9> uri_string:resolve(uri_string:recompose(#{path => "fo%3Ao/b:ar"}), "http:/localhost/a/b/c").
"http://localhost/a/b/fo%3Ao/b:ar"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants