Skip to content

Conversation

@gkreitz
Copy link
Contributor

@gkreitz gkreitz commented Nov 29, 2024

Fixes the regression in Smarty 5 where a compiler function using unnamed arguments threw a "Too many shorthand
attributes" error, and adds unit test coverage.

Fixes #1085

// shorthand attribute ?
} elseif (isset($this->shorttag_order[$key])) {
$_indexed_attr[$this->shorttag_order[$key]] = $mixed;
} elseif (!is_null($this->getShorthandOrder($key))) {
Copy link
Contributor Author

@gkreitz gkreitz Nov 29, 2024

Choose a reason for hiding this comment

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

I think the type of $key is always int here, based on the fact that it looks like $attributes is a list<mixed> from the usage, but I do not know enough about the code base to know. If my assumption is incorrect, the type of the argument to getShorthandOrder needs to be changed to avoid crashing.

Copy link
Member

Choose a reason for hiding this comment

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

Well, all the unit tests pass and I haven't found any references to shorttag_order in the source that suggest other keys. But as you noted, it only looks that way and is not guaranteed. Just to be safe, I'd prefer to allow a mixed type for the key param to getShorthandOrder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the slow response. I removed the php type annotations to be on the safe side.

gkreitz added a commit to gkreitz/smarty that referenced this pull request Jan 17, 2025
From usage, it very much looks like the type will always be int,
but on the off chance there is some code path where this gets called with
something else, type was widened to mixed for now, per disussion in smarty-php#1088
@gkreitz gkreitz force-pushed the 1085_unnamed_compiler_arguments branch from 9bb3447 to 91dd198 Compare January 17, 2025 09:35
From usage, it very much looks like the type will always be int,
but on the off chance there is some code path where this gets called with
something else, type was widened to mixed for now, per disussion in smarty-php#1088
@gkreitz gkreitz force-pushed the 1085_unnamed_compiler_arguments branch from 91dd198 to 0d24f1d Compare January 17, 2025 09:41
@niemela
Copy link

niemela commented Mar 2, 2025

Gentle nudge to merge this if possible?

@niemela
Copy link

niemela commented Sep 12, 2025

@wisskid Could this be merged? (Or another fix to #1085)?

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.

A compiler plugin that takes unnamed arguments throws "Too many shorthand attributes" in Smarty 5

3 participants