-
Notifications
You must be signed in to change notification settings - Fork 154
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
Emogrifier turns {} into %7B and %7D #646
Comments
This is not a UTF-8 encoding issue, but the correct representation (encoding) of a href attribute value in HTML. Depending on how you replace your template variables (placeholders), one quick solution would be to also encode the placeholder before the replace: str_replace(rawurlencode('{placeholder}'), 'https://any.url.here'); |
This is a bug in the emogrifier. I'm replacing the placeholder after the emogrify process but the placeholder is broken after merge css to the html with the help of emogrifier: #98 |
I've temporarily fixed it with this workaround after the emogrify process but in my eyes this is a bug which needs to be fixed:
|
Please note that Emogrifier uses DOM to work with HTML and the encoding we are talking about in this thread is a direct result of DOMDocument::saveHTML(). Please check here: DOMDocument::saveHTML() behaviour example. You are right that this behaviour is messing up template variables, just like #98 also described this behaviour and it seems there was a solution (#170) for it back then, but apparently that code was removed from the code since then. We will revisit this in the future... to make preserving template variables more straightforward with Emogrifier. Thank you for your feedback! |
The code from #170 was not removed - we have only refactored the corresponding unit test: So #170 is still fixed, and this is a separate issue with the curly braces. @Johnny99211 Would you be willing to create a PR that extends this existing test to curly braces (and also the corresponding tests for AbstractHtmlProcessor and CssInliner) and add a fix for this? |
For the record, my educated guess is that for href attributes, the value is expected to be a URL, that |
Yes, this is exactly what I was trying to describe above. It is definitely not a bug from Emogrifier, since this behaviour is inherited from However, given the fact that in many cases Emogrifier is used in a combination with some sort of templating system (which may use URL-encodable characters as template variable delimiters), we should see whether there would be some straightforward solution to not "break" these template variables during processing. |
Maybe we can add some What do you think? |
The new test shows that issue #646 only affects attribute values, not text nodes.
Architecturally this seems ok. In terms of implementation, there are a couple of possible approaches that may be viable and would avoid needing to specify which characters should not be URL-encoded:
I don't know if this feature affects other attributes, such as |
The new test shows that issue #646 only affects attribute values, not text nodes.
i have same problems |
Unfortunately this is an issue with PHP DOM, which Emogrifier uses out of necessity. There is no easy solution for this within Emogrifier. The correct place for a fix is within the PHP DOM component. The fix there would be fairly simple: remember what was read in, and if it hasn't been modified, write it out exactcly the same. I would suggest logging a bug against PHP, perhaps first looking for an existing match, at https://bugs.php.net/ Due to the intricacy of what may or may not need escaping, there is no realistic chance that we would be able to provide a solution within Emogrifier. @oliverklee, I think we should close this, for that reason, and mention it in the caveats in the readme. Failing a fix in PHP DOM, your best bet would be one of the workarounds suggested early on in this thread. |
Agreed. Would you be willing to add this to the README, @JakeQZ ? |
I'm currently setting up an email template which has two parts: The HTML and the CSS. To put everything together and merge the HTML with the CSS I'm using the PHP Emogrifier.
Now I've found out that when I emogrify the two elements that there is a problem with the uft-8 encoding.
All works like Ä, Ü, Ö are correctly displayed but when I put a link like this here into the content, the utf-8 encoding don't works for this element:
Before emogrify:
After emogrify:
So as you can see the href is broken which is set with a placeholder which gets replaced with the correct link after the emogrify process:
The text was updated successfully, but these errors were encountered: