Skip to content

Conversation

@OutlawPlz
Copy link

Ciao!

Since Laravel route names are strings and can contain virtually any character, I've added a regex that replaces characters that are invalid in JS with an underscore.

Currently, Wayfinder generates the JS file without verifying that the function name is valid. No exception is thrown, but the generated file contains invalid JavaScript. With this change, a route name like example@test would generate a function named example_test. The regex used /[^\p{L}\p{Nd}_$]/u covers the most common cases, but it could be made more permissive if desired to fully comply with the ECMAScript specification.

What do you think about this approach? Alternatively, we could throw an exception when encountering invalid characters instead of silently replacing them, to make users aware that their route names won't work with Wayfinder.

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

Successfully merging this pull request may close these issues.

1 participant