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

Chained modifiers, unexpected results. #327

Closed
P-a-d-r-a-i-g opened this issue Jan 10, 2017 · 7 comments
Closed

Chained modifiers, unexpected results. #327

P-a-d-r-a-i-g opened this issue Jan 10, 2017 · 7 comments

Comments

@P-a-d-r-a-i-g
Copy link

P-a-d-r-a-i-g commented Jan 10, 2017

The first case below comes from a Smarty2 script which works fine, but once applied to Smarty3.1.x and up it breaks giving an unexpected value.

The issue stems from the -4 being used in substr and the cat after it. If the - sign is removed, the functions works as expected, albeit the other way around.

Is this a Smarty bug?

The following is a simple test script with expected and actual results.

{assign var="aFile" value="somefile.xyz"|substr:0:-4|cat:".ext"}
<!-- Result expected: somefile.ext -->
<!-- Actual result: somefile -->
{$aFile}

{assign var="aFile" value="somefile.xyz"|substr:0:4|cat:".ext"}
<!-- Result expected: some.ext -->
<!-- Actual result: some.ext -->
{$aFile}

{assign var="aFile" value=("somefile.xyz"|substr:0:-4)|cat:".ext"}
<!-- Result expected: somefile.ext -->
<!-- Actual result: somefile.ext -->
{$aFile}

{assign var="aFile" value="somefile.xyz"|substr:0:-4}
{assign var="aFile" value=$aFile|cat:".ext"}
<!-- Result expected: somefile.ext -->
<!-- Actual result: somefile.ext -->
{$aFile}

{assign var="aFile" value="somefile.xyz"|substr:0:-(4)|cat:".ext"}
<!-- Result expected: somefile.ext -->
<!-- Actual result: somefile -->
{$aFile}

{assign var="aFile" value="somefile.xyz"|substr:0:(-4)|cat:".ext"}
<!-- Result expected: somefile.ext -->
<!-- Actual result: somefile.ext -->
{$aFile}

{assign var="aFile" value=-4|cat:".ext"}
<!-- Result expected: -4.ext -->
<!-- Actual result: -4.ext -->
{$aFile}

{assign var="aFile" value=-4-4|cat:".ext"}
<!-- Result expected: -8.ext -->
<!-- Actual result: -8.ext -->
{$aFile}

Above code contained here:
test.tpl.txt

@P-a-d-r-a-i-g
Copy link
Author

In the compiled tpl, the first case is compiled as:

$_smarty_tpl->_assignInScope('aFile', substr("somefile.xyz",0,-(4).(".ext")));

We can see from this that -(4).(".ext") is trying to be used as the 3rd parameter of substr which is not what is expected and used to work fine with Smarty2.

@P-a-d-r-a-i-g
Copy link
Author

I've attached the whole compiled tpl of the test script above for reference

compiled.file.test.tpl.php.txt

@AnrDaemon
Copy link
Contributor

Any results of modifying an assignment is an undefined behavior.
Please do not do that. Better yet, do not use assignments in templates if at all possible.

@AnrDaemon
Copy link
Contributor

If you absolutely want to do it, please try the v3 syntax {$name=value}.

@uwetews
Copy link
Contributor

uwetews commented Aug 19, 2017

This is a bug on chained modifier when last modifier parameter is a signed value. I will fix that asap

@uwetews
Copy link
Contributor

uwetews commented Aug 19, 2017

AnrDaemon
It has nothing to do with the assign tag

@uwetews
Copy link
Contributor

uwetews commented Aug 26, 2017

The bugfix is now in the master branch and will later be included in 3.1.22

@uwetews uwetews closed this as completed Aug 26, 2017
uwetews added a commit that referenced this issue Oct 9, 2018
 - bugfix fix of 26.8.2017 #327
   modifier is applied to sum expression #491
 - bugfix indexed arrays could not be defined "array(...)""
uwetews added a commit that referenced this issue Oct 9, 2018
 - bugfix fix of 26.8.2017 #327
   modifier is applied to sum expression #491
 - bugfix indexed arrays could not be defined "array(...)""
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

3 participants