Discrepancy between logged server URL and the URL in the `jpserver-*-open.html` file
Description
When the default_url contains a hash (aka fragment) (our app uses vue-router with hash-based routing), e.g. default_url = /foo/#/workspace, there is a discrepancy between the full URL logged at startup vs the full URL in the jpserver-*-open.html file.
When the server starts up and logs the URL it is using
https://github.com/jupyter-server/jupyter_server/blob/2563baeca9575be7895930ada2b1d244f93e5163/jupyter_server/serverapp.py#L2153-L2158
https://github.com/jupyter-server/jupyter_server/blob/2563baeca9575be7895930ada2b1d244f93e5163/jupyter_server/serverapp.py#L2106-L2110
which results in
>>> parts = self._get_urlparts(include_token=True)
>>> list(parts)
[
'http',
'localhost:8888',
'/foo/#/workspace',
'',
'token=blahblah42',
'',
]
>>> parts.geturl()
'http://localhost:8888/foo/#/workspace?token=blahblah42'
This is incorrect as the token querystring has become part of the hash and therefore is not recognised as a querystring by the browser, and opening the URL results in the Jupyter page for logging in / entering the token manually.
Whereas the URL that gets outputted to the jpserver-xxxx-open.html file that actually gets opened is from
tornado.httputil.url_concat
https://github.com/jupyter-server/jupyter_server/blob/2563baeca9575be7895930ada2b1d244f93e5163/jupyter_server/serverapp.py#L2671-L2675
which results in
>>> url = 'foo/#/workspace'
>>> url = url_concat(url, {'token': self.token})
'foo/?token=blahblah42#/workspace'
>>> url_path_join(self.connection_url, url)
'http://localhost:8888/foo/?token=blahblah42#/workspace'
which is correct as the querystring comes before the hash and everything works properly.
Reproduce
- Use a
default_urlwith a hash in it
Expected behavior
When handling default_url it should account for the possibility of a hash/fragment.
I should be able to come up with a quick fix for this, having debugged the issue to this extent. Otherwise I would say it would be safer to handle the URL the same way in each of the two cases, rather than the current different handling.
Context
- Operating System and version: N/A
- Browser and version: N/A
- Jupyter Server version: 2.7
Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada: