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

Problem with negative look-behind causing Safari to explode #812

Open
tholder opened this issue Feb 3, 2025 · 2 comments
Open

Problem with negative look-behind causing Safari to explode #812

tholder opened this issue Feb 3, 2025 · 2 comments
Assignees

Comments

@tholder
Copy link

tholder commented Feb 3, 2025

Ziggy version

2.x

Laravel version

11

Description

I'm using Laravel with Inertia and React.

It's the (?i:BASE64|) part of the route and I believe it is because safari doesn't support a negative look-behind. Before I discovered the offending route (as safari is such a pain to debug in), I did manage to eliminate it with an amend on atomica-software#1

Fix is easy enough for me, but this is a nasty safari only problem that could catch people out.

Some references:

https://stackoverflow.com/questions/51568821/works-in-chrome-but-breaks-in-safari-invalid-regular-expression-invalid-group
https://caniuse.com/js-regexp-lookbehind

Ziggy call and context

Simple call to route().params.team

Could potentially just be useRoute() call. Had some issue determining this.

Ziggy configuration

"image.avatar": {
            "uri": "image/{type}/{id}/{hash}/{format?}",
            "methods": [
                "GET",
                "HEAD"
            ],
            "wheres": {
                "id": "[0-9]+|[0-9a-f\\-]+",
                "type": "user|contact",
                "format": "(?i:BASE64)|"
            },
            "parameters": [
                "type",
                "id",
                "hash",
                "format"
            ]
        },

Trimmed for sensitivity but this is the route causing a problem.

Route definition

Route::get('/image/{type}/{id}/{hash}/{format?}', [ImageResourceController::class, 'show'])
    ->name('image.avatar')
    ->where('type', 'user|contact')
    ->where('id', '[0-9]+|[0-9a-f\-]+')
    ->where('format', '(?i:BASE64)|')
    ->withoutMiddleware(['web']);
@bakerkretzmar
Copy link
Collaborator

What exactly is the error you're getting? Does it happen everywhere in your app when Ziggy loads or only when you're making specific calls using that route? Is it something inside Ziggy in combination with your route causing this error or is it just the (?i:...) that Safari can't handle?

@bakerkretzmar bakerkretzmar self-assigned this Feb 3, 2025
@tholder
Copy link
Author

tholder commented Feb 3, 2025

It blows up the entire app, the call to route().params I believe is what does it. Here is the console in Safari when I finally worked out what the issue was.

Not saying this is something that necessarily needs fixing because my route is not good and it was an easy fix, but, it took me days to debug this (mainly because Safari is a POS!).

Image

The error was "SyntaxError: Invalid regular expression: unrecognized character after (?"

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants