-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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 isTemplate to not return true for string containing ${{ #11315
Conversation
Hi @slackerzz
Also, please review the Backward Compatibility Guide for adding new constructor argument. |
You can run tests on local machine or wait for travis results |
We should come to conclusion in initial issue before processing this PR. |
I think that escaping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please expand \Magento\Cms\Test\Unit\Model\PageTest
with additional case and implement similar \Magento\Cms\Test\Unit\Model\BlockTest
for fixed case.
After all changes are made and all builds are green, please squash all changes into a single commit.
* | ||
* @return string mixed | ||
*/ | ||
public function escapeDollarSign($data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now this is just some Magento_Cms
-specific hack to overcome collision with JS templates syntax thus it should not be a part of Magento_Framework
.
to replace
${ with $ {
No need in HTML entity, just use unicode character. As we can simply do str_replace('${', '$<proper code>{')
I don't think there is a real need to do it as separate method.
If we would need something more than one-liner, the class could be something like \Magento\Cms\Model\PseudoEs6TemplateEscaper
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This collission happens with every text field in the Magento backend, not only in Magento_Cms
#10501 (comment).
According to me it doesn't make sense to put it in Magento_Cms
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${
in product/category name would be pretty strange. Only those places needs to be fixed where we normally use some {{ ... }}
now as a variable template.
My suggestion is: simply do str_replace
in place, as soon as this logic this be identified frequently reusable (hope no) it can be refactored into separate class in whatever module or framework itself is suitable (now it should not go outside Magento_Cms
, depending on use cases it may become a part of Magento_Backend
or Magento_Ui
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If someone sign up with a ${
inside the name, all the customer section in the backend is broken. Obviously it is not common, but we cannot trust user inputs.
${
should NEVER be saved as is, so it makes sense to add the `Escaper' class to escape every user/admin inputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Escaper
class is not needed currently at all as I already said.
If someone sign up with a
${
inside the name, all the customer section in the backend is broken.
This is a bit different story. In such case string replace does not make a lot of sense and also such situation never occurred before in reality. Please report it separately and we can discuss a fix for it then. I tend to forbidding such combination of symbols via validation.
@@ -45,6 +53,7 @@ public function execute() | |||
$resultRedirect = $this->resultRedirectFactory->create(); | |||
$data = $this->getRequest()->getPostValue(); | |||
if ($data) { | |||
$data['content'] = $this->escaper->escapeDollarSign($data['content']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest moving such logic to \Magento\Cms\Model\Block::beforeSave
.
@@ -77,6 +84,7 @@ public function execute() | |||
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ | |||
$resultRedirect = $this->resultRedirectFactory->create(); | |||
if ($data) { | |||
$data['content'] = $this->escaper->escapeDollarSign($data['content']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest moving such logic to \Magento\Cms\Model\Page::beforeSave
.
a46f25e
to
810efe1
Compare
810efe1
to
bac9576
Compare
Changed
isTemplate
in template.jsNow it returns
false
if value contains${{
Description
Fixed Issues (if relevant)
Manual testing scenarios
${{config path="web/unsecure/base_url"}}
as contentContribution checklist