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

Misleading basename warning message #605

Closed
misi444 opened this issue Jul 9, 2018 · 5 comments
Closed

Misleading basename warning message #605

misi444 opened this issue Jul 9, 2018 · 5 comments

Comments

@misi444
Copy link

misi444 commented Jul 9, 2018

Hello,

This is going to be quite considering the severance of the issue but maybe someone can point me somewhere though I know very well that the root of my main problem has nothing to do with the code in this repository. I just stumbled upon a minor issue during my research.

I am developing a React web application which needs to be called with a specific query string containing a parameter. My application needs to be integrated with a third-party proprietary component which renders a dynamic header and a footer in the application.

This header and footer contain <a> tags with the attribute href="#". Of course these links don't go anywhere but they have onclick handlers which expand/collapse menus etc. At least that's how they should work. But within the head there is a <base> tag which's value is the relative path to the root of the application but without the query string. This tag is rendered on the server and this makes sure that the application works the same way in different environments (e.g. http://example.com and http://example.com/Foo as well without any modifications).

However this gives me a headache right now as the relative anchor tags compute their absolute target urls relative to the base path. That does not include the query string and therefore upon clicking them the browser detects an URL change and performs a redirect instead of just appending the hashmark at the end of the URL.

So I have tried to modify the <base href>. If I change it in the inspector and append the query string, everything works fine. But if I change it in the code and try to load the application, nothing renders and there is no error message at all - except for a warning:

Warning: You are attempting to use a basename on a page whose URL path does not begin with the basename. Expected path "/Foo/?bar=777" to begin with "/Foo/?bar=777".

My issue lies here: the warning message is simply not true, because the strings are identical and therefore they both begin with one another. I have found that the relevant check originally tested this exact condition (indexOf... !== -1) described in the warning message, but in a later commit it has been replaced with a more advanced logic with regex matching etc: (e075087#diff-f62943cda47e8992518ce1f1e28f38c1)

But the warning message remained unchanged. I think this is misleading because it does not correctly describe the actual problem and states a fact which is false.

@ajhyndman
Copy link

I just ran into this today as well.

It looks like the issue is that hasBasename assumes that basename will never contain characters which have special meaning when interpreted as a regex, which is not guaranteed to be true.

A solution might be to use something like https://github.com/sindresorhus/escape-string-regexp to escape any such characters just before creating the regex to test.

@w33ble
Copy link

w33ble commented Jul 23, 2018

I think this is a duplicate of #564

@ajhyndman
Copy link

Actually, it looks like there are half a dozen of the same issue.

Earliest looks like #544

@w33ble
Copy link

w33ble commented Jul 23, 2018

Half a dozen issues to go with the half a dozen PRs I guess 😛

@mjackson
Copy link
Member

I merged #544 yesterday. This will be fixed in the 4.10 release.

@lock lock bot locked as resolved and limited conversation to collaborators May 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants