-
Notifications
You must be signed in to change notification settings - Fork 388
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
Do not escape query included in url launch parameter #1774
Do not escape query included in url launch parameter #1774
Conversation
0aff7c5
to
312e0d9
Compare
@manics I opened a PR to this PR fixing this: manics#8. Well, almost fixing it - you'll see it fails currently because the unencoded So our two options are:
I think (1) is ok, and we can sort of validate this by looking at the two reported URLs that had problems, and perhaps also look at our analytics event streams for paths with unencoded |
First of all was my test definitely correct? I wasn't completely sure whether the The main problem is the leading Edit: Feel free to rebase and force push if you want, otherwise I'll do it later |
Previously, if 'path' contained query parameters, they were not treated correctly. Here they do get treated correctly, although new constructor mechanics mean that the serverUrl we get back from binderhub can't have query parameters now.
0f2f23a
to
b93f4e0
Compare
Rebased |
@manics could you update the title of this PR as well to reflect its more than just test related now? |
Done! |
I added an additional test specifically using nbgitpuller, and showing that URL encoding seems to be done now just the right amount, rather than double or none. |
// Ensure there is a trailing / in serverUrl | ||
if (!url.pathname.endsWith("/")) { | ||
url.pathname += "/"; | ||
} |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
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.
Ah!
I think there is a breaking change here.
-url.pathname = url.pathname + "/doc/tree/" + encodeURI(path);
+url = new URL("doc/tree/" + encodeURI(path), url);
These are different I think, to verify that:
console.log("old new behavior presented below")
let nonRoot1 = new URL("https://developer.mozilla.org/test")
nonRoot1.pathname = nonRoot1.pathname.replace(/\/$/, "");
nonRoot1.pathname = nonRoot1.pathname + "/doc/tree/"
console.log(nonRoot1.href)
let root1 = new URL("https://developer.mozilla.org")
root1.pathname = root1.pathname.replace(/\/$/, "");
root1.pathname = root1.pathname + "/doc/tree/"
console.log(root1.href)
console.log("new behavior comes below")
let nonRoot2 = new URL("https://developer.mozilla.org/test")
let newNonRoot2 = new URL("doc/tree", nonRoot2)
console.log(newNonRoot2.href)
let root2 = new URL("https://developer.mozilla.org")
let newRoot2 = new URL("doc/tree", root2)
console.log(newRoot2.href)
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.
The trailing /
in the pathname is required (/test/
not /test
), it affects how the parts are joined.
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.
Yeah, preventing this behavior is why we enforce path ends with /
even if it is not passed in. So baseUrl will never not have trailing slash. As @manics says, it affects how parts are joined.
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.
@consideRatio I added another test case to demonstrate why I think this is fine.
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.
Hmmm but what if baseUrl is a jupyterhub with a prefix?
Note that now, but not before, the nonRoot examples doesnt have the /test prefix in the path?
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.
If you both think there is no loss of path issue, this is good even if i dont understand the details.
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.
Hmmm but what if baseUrl is a jupyterhub with a prefix?
The code appends a trailing /
if there isn't one, so this should behave correctly
let nonRoot2 = new URL("https://developer.mozilla.org/test")
if (!nonRoot2.pathname.endsWith("/")) {
nonRoot2.pathname += "/";
}
let newNonRoot2 = new URL("doc/tree", nonRoot2)
console.log(newNonRoot2.href)
https://developer.mozilla.org/test/doc/tree
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.
Ah, so the href can be the same for a URL object, but end up resulting in a different URL when used to construct another. I think i got it and this LGTM
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 looks good to me from what I can tell, and with the added tests, we should be in better shape than we already are I think.
I'm not sure about the expected behavior and such =/
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.
See https://github.com/jupyterhub/binderhub/pull/1774/files#r1358088687, I think this isn't correct yet because there is a behavior change unrelated to escaping.
ok, I tested this locally. You can first see me try an nbgitpuller link on the main branch, and it fails. Then I switch to this branch, and it succeeds (once if hard refresh the page to get new JS). Screen.Recording.2023-10-14.at.12.57.24.AM.movThank you for working on this @manics and thanks for the review, @consideRatio. I am hoping that my cleanup + automated testing efforts will allow us to build more of these things without breaking. |
I'm not sure if this test is correct, but I think it illustrates the bug in
jupyterhub/nbgitpuller#329
https://discourse.jupyter.org/t/nb-on-binder-with-parameters-now-resulting-in-404/21860