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

Dash in parameter name breaks shortcodes Twig filter #125

Open
dmik opened this issue Jul 16, 2024 · 2 comments
Open

Dash in parameter name breaks shortcodes Twig filter #125

dmik opened this issue Jul 16, 2024 · 2 comments

Comments

@dmik
Copy link

dmik commented Jul 16, 2024

I'm trying out shortcodes-core v5.2.0 and it appears that having a parameter with a name containing a dash completely breaks it: the handler function is simply not called in this case.

Steps to reproduce:

  1. Install grav-admin-v1.7.46.
  2. Edit themes/quark/templates/partials/footer.html.twig and add {{ '[fa=cog my-param /]'|shortcodes|raw }} somewhere inside the <p> tag.

The output in HTML will be [fa=cog my-param /], i.e. the shortcode's literal without any transformatin (not a suprise as logging shows that its handler is not called at all).

If you change the short code to just {{ '[fa=cog myparam /]'|shortcodes|raw }} (notice no dash), all works — the handler is called and the icon appears.

Note that there is no such a problem when the same shortcode (i.e. with the dash in the parameter name) is used inside a .md file — all works correctly in this case and the icon properly is generated as well. So the problem only appears with the shortcodes filter (with or without raw).

@pmoreno-rodriguez
Copy link

Try to change your user/plugins/shortcode-core/vendor/thunderer/shortcode/src/Utility/RegexBuilderUtility.php file in the following way:

line 43:
return '~(?:\s*([\w-]+(?:'.$complex.'|'.$simple.'|'.$empty.')))~us';

line 66:
$parameters = '(?<parameters>(?:\s*(?:[\w-]+(?:'.$equalsSpaced.$complex.'|'.$equalsSpaced.$simple.'|'.$empty.')))*)';

Try it and if it works correctly, I will propose a pull request with these changes.

@dmik
Copy link
Author

dmik commented Aug 14, 2024

@pmoreno-rodriguez Just tried what you said and — yes, this fixes the problem here, 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