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

(dev/core#4303) Allow {htxt} guard to accommodate variable ID #26298

Merged
merged 3 commits into from
May 23, 2023

Conversation

totten
Copy link
Member

@totten totten commented May 22, 2023

Ovreview

Fix recent regression (reported in https://lab.civicrm.org/dev/core/-/issues/4303) where CustomField.hlp generates an error while processing {htxt}.

Before

{htxt} guard works with static IDs ({htxt id="abc"})

After

{htxt} guard with with variable ID ({htxt id=$abc})

Comments

In my copy of universe, there's a similar construction in nz.co.fuzion.entitysetting (entitysettingscommon.hlp). However, in that case, it appears to loop through a list of settings and (conditionally) generates help blobs for each (but ultimately only needs to display one). I haven't actually r-run that extension, but I'd be hopeful that this addresses it as well.

totten added 2 commits May 21, 2023 22:26
Before
------

`{htxt}` guard works with static IDs (`{htxt id="abc"}`)

After
-----

`{htxt}` guard with with variable ID (`{htxt id=$abc}`)

Comments
--------

As discussed in dev/core#4303, one relevant use-case comes from `CustomField.hlp`.

In my copy of universe, there's a similar construction in
`nz.co.fuzion.entitysetting` (`entitysettingscommon.hlp`).
@civibot
Copy link

civibot bot commented May 22, 2023

(Standard links)

@civibot civibot bot added the 5.62 label May 22, 2023
@eileenmcnaughton
Copy link
Contributor

@agileware-justin

@agileware-justin
Copy link
Contributor

@larssandergreen

@totten
Copy link
Member Author

totten commented May 22, 2023

Note: You will probably need to flush caches if applying the patch directly (without a version-change or upgrade).

@@ -22,6 +22,10 @@ function smarty_prefilter_htxtFilter($tpl_source, &$smarty) {
$htxts++;
return sprintf('{if $id == %s}%s', $m[1], $m[0]);
},
'/\{htxt id=(\$\w+)}/' => function ($m) use (&$htxts) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would not match {htxt id=$foo otherstuff}, which seems like it should be valid. Seems safest just to remove that }.

Copy link
Member Author

Choose a reason for hiding this comment

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

@larssandergreen That's correct, it doesn't/didn't match otherstuff.

Regarding this specific example, we could treat either } or as terminating the id=... phrase. This would allow subsequent parameters.

I wouldn't exactly drop the }. Consider text like {htxt id=$foo.bar} or {htxt id=$foo[bar]} or {htxt id=$foo"bar"} or {htxt id=$foo{bar}}:

  • If the regex has no closing marker (id=(\$\w+)), then it does a partial match -- matching id=$foo and ignoring .bar or [bar] or "bar" or {bar}. I expect that to produce some weird bug.
  • If the regex has a closing marker (id=(\$\w+)[} ]), then it will not match any of those examples. htxtFilter will throw an exception (Invalid {htxt} tag), which points you to the right element.

Within the world of "unsupported edge-cases", the explicit error is better, no?

Anyway, the example you gave ( otherstuff) should be fairly easy to accommodate by accepting as another closing-marker. I'm pushing up a commit to do that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense.

@larssandergreen
Copy link
Contributor

Looks good to me other than that one detail, but the details of the test are over my head so I can't comment on that.
r-run confirms this resolves the issue.

Also: tighten the handling of ' and " to ensure that they are matched properly.
@eileenmcnaughton
Copy link
Contributor

OK - that looks like a thumbs up from @larssandergreen after some good review - merging

@totten we should push out...

@eileenmcnaughton eileenmcnaughton merged commit 02d6f43 into civicrm:5.62 May 23, 2023
@larssandergreen
Copy link
Contributor

@totten If you're pushing a new point version for this, I think it would make sense to include this related fix #26079 (which is actually worse in terms of impact, I think, see this recent issue).

@agileware-justin
Copy link
Contributor

agileware-justin commented May 23, 2023

Good point @larssandergreen - if that related PR had been included in the last CV point release then the problem would have not been triggered in our case or that of the related gitlab.

@totten totten deleted the 5.62-htxt-dynamic branch May 23, 2023 21:09
@totten
Copy link
Member Author

totten commented May 23, 2023

Ooph, yeah, agree that flavor of the bug is more severe. It's included in 5.61 PR.

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

Successfully merging this pull request may close these issues.

4 participants