spatie/laravel-menu

Invalid Scheme using javascript:;

Closed this issue · 4 comments

For a dropdown menu I'm using a "javascript:;" as href in a parent item.

Whenever I add a Link method with URL: javascript:; on a Link object:

Link::to("javascript:;", "Demo), I get a Laravel Exception on the setActive() method:

The scheme javascript isn't valid. It should be either http or https

Spatie\Url\Exceptions\InvalidArgument::invalidScheme
vendor/spatie/url/src/Exceptions/InvalidArgument.php:11

Is there any way to resolve this matter without having to enter the <a href> via the HTML method?

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

Reopen

We're leaving it closed as we ourselves and others haven't come across this bug.

Feel free to PR a fix, make sure to include tests.

I'm having the same problem. I'm using the package to output a menu for an admin panel and for some of the links I'm linking to javascript:void(0). After looking into the code I discovered that the issue is caused when a person uses the setActiveFromRequest() method because this results in the fromString() method being called Spatie\Url\Url package which the Laravel menu package uses when setActiveFromRequest() is called. The fromString method uses parse_url and the scheme parameter is seen as "javascript". The next few lines of code check the scheme and "javascript" is not seen as a valid scheme and so the error is thrown.

It would be great if this can be amended to check for the existence of url's that use javascript and avoid using parse_url on these types of url's.