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

Deserialize the image size when using maxWidth #2632

Merged
merged 4 commits into from Jan 15, 2021

Conversation

m-vo
Copy link
Member

@m-vo m-vo commented Jan 12, 2021

Q A
Fixed issues -
Docs PR or issue -

We must deserialize the image size when someone is using the legacy maxWidth/maxImageWidth parameter/config option in Controller::addImageToTemplate.

Proof of failing test is in 92ad5f3.

fritzmg
fritzmg previously approved these changes Jan 12, 2021
@leofeyer leofeyer added the bug label Jan 12, 2021
@leofeyer leofeyer added this to the 4.10 milestone Jan 12, 2021
@@ -1589,6 +1589,8 @@ public static function addImageToTemplate($template, array $rowData, $maxWidth =
}

// Normalize size
$size = StringUtil::deserialize($size);
Copy link
Member

Choose a reason for hiding this comment

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

This cannot be the correct place to deserialize the string. It should be in line 1605 inside the else condition IMHO, don't you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

We're also deserializing any input in the ImageFactory and that's what was in place before as well.

So - in theory - someone could rely on it working with a single serialized integer for example.

Copy link
Member

Choose a reason for hiding this comment

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

That is weird as well then. 😄 If we know that $size can be numeric or an object, why would we try to deserialize it without checking if deserializing is necessary first?

Copy link
Member Author

Choose a reason for hiding this comment

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

It could for instance be a numeric value ("123") or a serialized numeric value (s:3:"123";). This is at least what the old implementation allowed and the current PictureFactory is allowing.

In fact $size can imo be one of int|string|array|PictureConfiguration|null with string including all possible serialized versions ofint|string|array|null.

Copy link
Member

@leofeyer leofeyer Jan 13, 2021

Choose a reason for hiding this comment

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

You are missing the point.

$size = StringUtil::deserialize($size);

if ($size instanceof PictureConfiguration)
{
    return array($size, $margin);
}

StringUtil::deserialize() does not allow serialized objects, so this condition can only be true if $size is already an object before it is passed to StringUtil::deserialize(). It therefore does not make sense to have the instanceof check after StringUtil::deserialize(). It should be:

if ($size instanceof PictureConfiguration)
{
    return array($size, $margin);
}

$size = StringUtil::deserialize($size);

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I know and StringUtil::deserialize() is the identity function for objects 🙂. I was referring to your initial comment suggesting to put the line in the else clause where it would miss the serialized numeric case.

Nevermind, I moved it after the instanceof check in 1b0bc6b.

ausi
ausi previously approved these changes Jan 13, 2021
@m-vo m-vo dismissed stale reviews from ausi and fritzmg via 1b0bc6b January 13, 2021 12:27
@leofeyer leofeyer merged commit 61c3f48 into contao:4.10 Jan 15, 2021
@leofeyer
Copy link
Member

Thank you @m-vo.

@leofeyer leofeyer changed the title Deserialize image size when using maxWidth Deserialize the image size when using maxWidth Jan 21, 2021
AlexejKossmann pushed a commit to AlexejKossmann/contao that referenced this pull request Apr 6, 2021
Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | -
| Docs PR or issue | -

We must deserialize the image size when someone is using the legacy `maxWidth`/`maxImageWidth` parameter/config option in `Controller::addImageToTemplate`.

Proof of failing test is in 92ad5f3.

Commits
-------

92ad5f3 test maxWidth with serialized size
72763bc always deserialize size when using maxWidth fallback
1b0bc6b deserialize after checking for object instance
aaf92e5 Merge branch '4.10' into bugfix/max-width-deserialize-size
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.

None yet

4 participants