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

Fix non-existent snippet tags being broken up by an @ tag #16322

Draft
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

Conversation

Mark-H
Copy link
Collaborator

@Mark-H Mark-H commented Dec 3, 2022

What does it do?

Described in #16318, if a non-existent snippet tag is found within an output filter, an @ tag inside the filter can cause the output to break.

The provided example where xxx doesn't exist:

[[+xyz:empty=`
aaa
[[xxx? &x=`bbb@ccc`]]
ddd
`]]
eee

is getting broken up by modTag/modElement::getPropertySet on the @, treating the part in front of it as the name of the tag/element, including half the snippet tag.

This fix makes sure that it only considers the bit up to the first :.

To ensure property sets continue to work, I wanted to add some property set tests but I can't get this structure:

[[!Snippet@PropSet:default=`foo`]]

to return anything when the snippet returns an empty value. If someone can figure out why that's not working (in either the test or real world cases!) that would be great.

Why is it needed?

Make parser more resilient.

How to test

Unit tests or create your own similar test cases with snippets on a resource.

Related issue(s)/PR(s)

Fixes #16318

@cla-bot cla-bot bot added the cla-signed CLA confirmed for contributors to this PR. label Dec 3, 2022
],
[
'This is a [[snippetName@propSetName:default=`default value`]]',
'This is a default value',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the test that's failing. The snippet returns the value of the prop property, which doesn't exist in this scenario, so the snippet returns an empty value. That should make it return the default filter, but instead it returns nothing at all (This is a ).

Can reproduce the same behavior when creating things manually on a template/resource, so that suggests something is broken?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a chance this may've been related to #16337, so will need to test again.

@theboxer
Copy link
Member

@Mark-H is this still in a draft state?

@Mark-H
Copy link
Collaborator Author

Mark-H commented Dec 3, 2024

Yes, I was hoping for some help trying to figure out the failing test but didn't get any.

smg6511 added a commit to smg6511/revolution that referenced this pull request Jan 21, 2025
Fixes issue with default value not working when prop set is specified in an Element call
if (strpos($tagName, '@') !== false) {
$split = xPDO:: escSplit('@', $tagName);
$psName = $split[1];
$this->set('name', $split[0] . $remainingTag);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is where the issue lies (same goes in the modTag file L520). Here, when modifiers are present, you end up with snippetNamedefault=`default val` instead of snippetName:default=`default val` (note the colon missing in the former) when setting the name on the Element.

Copy link
Collaborator

@smg6511 smg6511 Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple other things:

  • I made my own submission for this (Follow up to 16322: Fix non-existent snippet tags being broken up by an @ tag #16682) only because it was easier to do, particularly because I wanted to make sure whatever I came up with passed on the latest 3.1 dev branch and I've been having issues getting the unit tests to run on my local dev install.
  • I refactored how the two parts of the tag are broken up (using substr approach instead of explode/implode), as it seemed easier to see what was happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed CLA confirmed for contributors to this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

At sign (@) inside chunk parameter value nested into tag output filter breaks tag parsing
3 participants