spatie / laravel-menu

Html menu generator for Laravel
https://freek.dev/414-a-modern-package-to-generate-html-menus
MIT License
914 stars 83 forks source link

Invalid Scheme using javascript:; #99

Closed i6media closed 3 years ago

i6media commented 4 years ago

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?

spatie-bot commented 3 years ago

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.

i6media commented 3 years ago

Reopen

freekmurze commented 3 years ago

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.

ChristinePHP commented 3 years ago

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.