Problem/Motivation
We have some places in code where we pass the result from t() to Html::escape().
This causes errors, because Html::escape() expects a string.
Besides, it is quite uncommon to further escape the result of t().
Also, we would call $this->t() and not t()..
Steps to reproduce
Visit /admin/config/l10n-server/connectors
For one of the connectors, choose "Parse" or "Scan" from "Operations" column.
In the confirm form, choose "Confirm".
Expected: Operation completes.
Actual: Error "TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, Drupal\Core\StringTranslation\TranslatableMarkup given, called in /var/www/html/l10n_server/src/Form/ConnectorBatchConfirmScanForm.php"
Proposed resolution
Simple solution: Cast to string before calling Html::escape():
Html::escape((string) t(..));
Real solution: Review why we are translating and escaping this stuff.
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork l10n_server-3563271
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
donquixote commentedComment #4
donquixote commentedWe could start with this simple fix but then keep the issue open to find a proper solution.
Comment #5
fmb commentedI think we should just get rid of Html::escape(). Can you manually test without it?
Not in a static context.
Also, "hase" is just a typo for "has".
Comment #6
donquixote commentedAlright.
I had a look how core handles bad html in t().
As an example, I looked at translated strings in block UI.
I tried with `
<script>alert("hello")</script>` and with `<p>` (open tag without close tag).Here "unfiltered" means that the alert pops up and the markup is garbled thanks to the incomplete markup.
<p>` tag)As a conclusion, I'd say it is safe to drop the Html::escape(), and treat the result of t() as trustworthy, as this is also what core does.
Comment #7
donquixote commentedThe next question would be:
Does the $context['results'] in a batch operation allow html?
It seems yes: In _node_mass_update_batch_process() we see a link being assigned.
This means we don't need to remove html.
Comment #8
donquixote commentedI want to mention that we currently cannot test the specific functionality in l10n_server until we fix it, which is out of scope for this issue.
Comment #9
donquixote commentedComment #15
fmb commented