Suggested commit message:
Issue #2319233 by Sutharsan, sardara, ChristianAdamski, akoe: Fixed visible HTML on Available translation updates page.

Problem/Motivation

Double escaped string in Available translation update text. See screenshot:

Proposed resolution

Mark string as safe.

Steps to reproduce

1. Install drupal 8. Make sure automatic updates are switched off.
2. Enable Language module.
3. Enable Interface translation.
4. Add a language on admin/config/regional/language
5. Enable the Update manager module.
6. Go to admin/reports/translations, the status of the added language is "Missing translations for one project
Drupal core (8.0.0-beta4). File not found at http://ftp.drupal.org/files/translations/8.x/drupal/drupal-8.0.0-beta4.h... nor at translations://drupal-8.0.0-beta4.hu.po" or similar.

Remaining tasks

Decide whether variables containing safe string(s) should be renamed, or variables/logic should be moved from the preprocess to the the template.

 

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Update the issue summary Novice Instructions
Manually test the patch Novice Instructions
Add steps to reproduce the issue Novice Instructions
Embed before and after screenshots in the issue summary Novice Instructions
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards Instructions
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sutharsan’s picture

Status: Active » Needs review
FileSize
817 bytes

Although, this patch has a working solution, I am not yet convinced that it is a proper one. The string which is marked safe is a concatenation of a translated string and a variable $update['info']. The latter is the result of TranslationStatusForm::createInfoString(). Should we improve the code by renaming the variables to $update['safe_info'] and the method to TranslationStatusForm::createSafeInfoString()?

Sutharsan’s picture

Issue tags: +D8MI, +language-ui
oriol_e9g’s picture

I think that you can use an inline template:

From:

$string = t('My string');

To:

$string = array(
  'data' => array(
    '#type' => 'inline_template',
    '#template' => '{{ text }}',
      '#context' => array(
        'text' => t('My string'),
    ),
  )
);
Sutharsan’s picture

I'm not convinced that an inline template for the final string is worth while. It would look like this:

        $releases[] = array(
          'data' => array(
            '#type' => 'inline_template',
            '#template' => '{% trans %}{{ module }} ({{ version }}). {{ info }}{% endtrans %}',
            '#context' => array(
              'module' => $update['name'],
              'version' => $version,
              'info' => $update['info'],
            ),
          )
        );

I've made a slight change to the #1 patch. The 'info' must be inside the translatable string, otherwise it would fail with RTL languages.

Status: Needs review » Needs work

The last submitted patch, 4: locale-double-escaped-string-2319233-4.patch, failed testing.

Sutharsan’s picture

Status: Needs work » Needs review
FileSize
2 KB
2.17 KB

On second thought, this is not even a "double escape" problem, it is actually a wrong string concatenation.

roderik’s picture

Issue summary: View changes

Marking for Amsterdam. The patch is reviewable by experienced Drupal(contrib) people who know t(). Other tasks can be done by everyone (like updating the issue summary for the committers, because it has changed direction).

sardara’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Amsterdam2014
FileSize
98.92 KB

I could reproduce the bug in my local environment. After applying the last patch, the bug is resolved.
See screenshot:

The path follows the coding standards.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: locale-double-escaped-string-2319233-6.patch, failed testing.

sardara’s picture

Status: Needs work » Needs review
FileSize
2.01 KB

Since the core has changed, the patch doesn't apply anymore.
Re-rolled against latest head.

ChristianAdamski’s picture

Oh, I just found this issue :(

We solved the same thing at https://www.drupal.org/node/2349749

Difference is: we used an inline_template.

I am not sure, which solution is the better way to go.

Status: Needs review » Needs work

The last submitted patch, 10: locale-double-escaped-string-2319233-10.patch, failed testing.

akoe’s picture

Just tested this solution with patch #10 locally, it worked and successfully solved the issue.

We looked into possible solutions in https://www.drupal.org/node/2349749 and actually i prefer this solution since it seem easier.

roderik’s picture

Status: Needs work » Needs review

Those errors seem random. Re-testing...

star-szr’s picture

Adding parent issue relationship.

jibran’s picture

Issue tags: +SafeMarkup
roderik’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

OK; since this patch was already needs-review in #10 (the failure was indeed 'random' at busy Drupalcon A'dam) and people agree that this is the best solution...

... I did a quick review and can set RTBC, I think. Patch still applies with minimal offset + fuzz, and with a 2-line patch that should be OK.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 10: locale-double-escaped-string-2319233-10.patch, failed testing.

Sutharsan’s picture

Issue tags: +Needs reroll
lauriii’s picture

roderik’s picture

Status: Needs review » Reviewed & tested by the community

OK I'll remember to reroll patches with minimal offset + fuzz next time. For the rest; as #18.

(checked things are still the same.)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/locale/locale.pages.inc
@@ -125,7 +125,7 @@ function template_preprocess_locale_translation_update_info(array &$variables) {
-        $releases[] = t('@module (@version).', array('@module' => $update['name'], '@version' => $version)) . ' ' . $update['info'];
+        $releases[] = t('@module (@version). !info', array('@module' => $update['name'], '@version' => $version, '!info' => $update['info']));

I'm not sure why we are using t() here.

subhojit777’s picture

Assigned: Unassigned » subhojit777
subhojit777’s picture

Assigned: subhojit777 » Unassigned
Status: Needs work » Needs review
FileSize
3.88 KB
3.97 KB

Using String::format()

lauriii’s picture

Using String::format is a good change. I was about to RTBC this but only thing I'm concerned still is whether we can use multi line array syntax while setting parameter for the function call or not.

Gábor Hojtsy’s picture

Status: Needs review » Needs work
Issue tags: +Novice
+++ b/core/modules/locale/locale.pages.inc
@@ -60,7 +61,10 @@ function template_preprocess_locale_translation_update_info(array &$variables) {
-        $releases[] = t('@module (@date)', array('@module' => $update['name'], '@date' => format_date($update['timestamp'], 'html_date')));
+        $releases[] = String::format('@module (@date)', array(
+          '@module' => $update['name'],
+          '@date' => format_date($update['timestamp'], 'html_date'),
+        ));

Why would String::format() not do the same escaping as t() does? I don't see how this is fixing the issue?

BTW the multiline array syntax is no problem.

subhojit777’s picture

Issue tags: +dcdelhi

We are not translating anything here. We are showing some strings in placeholder. I do not think we should use t() for that, String::format() would suffice in this case. That is what @alexpott told in #23 and we talked about this in IRC.

Gábor Hojtsy’s picture

That does not answer my question. '@module (@date)' should escape the module name and date for output the same as it would in t() that you are removing. Switching from t() to String::format() should not change how the values are escaped and therefore should not fix this bug. Or what am I missing?

balagan’s picture

Issue summary: View changes
andythomnz’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: +CatalystAcademy
FileSize
85.28 KB

Hi, I have installed some modules in my Drupal environment and applied the patch. It appears to solve the problem, although I also don't understand why, Gábor.

Screenshot attached

herom’s picture

This is to answer @Gábor's question of how the bug is being fixed.

-        $releases[] = t('@module (@date)', array('@module' => $update['name'], '@date' => format_date($update['timestamp'], 'html_date')));
+        $releases[] = String::format('@module (@date)', array(
+          '@module' => $update['name'],
+          '@date' => format_date($update['timestamp'], 'html_date'),
+        ));

This change is out-of-scope of this issue. It's ok to commit this too, but this string was escaped correctly before and after the patch.

-        $releases[] = t('@module (@version).', array('@module' => $update['name'], '@version' => $version)) . ' ' . $update['info'];
+        $releases[] = String::format('@module (@version). !info', array(
+          '@module' => $update['name'],
+          '@version' => $version,
+          '!info' => $update['info'],
+        ));

The change that fixes this issue is here, by moving the "!info" part into String::format (or t(), makes no difference). The double-escaping happened because only the '@module (@version).' part of the string was being marked as safe in t(), and when the whole string was printed, it was unrecognized and escaped again.

Gábor Hojtsy’s picture

Issue tags: +sprint

So I needed to go one step further in understanding. String::format() adds the string to the SafeMarkup storage, so it will not be escaped later. So bringing strings under that storage protects them from being escaped later again. Agreed with the RTBC then.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed f758884 and pushed to 8.0.x. Thanks!

  • alexpott committed f758884 on 8.0.x
    Issue #2319233 by Sutharsan, subhojit777, sardara, lauriii, andythomnz:...
Gábor Hojtsy’s picture

Issue tags: -sprint

Superb, thanks all!

subhojit777’s picture

@herom++ Nice explanation. Thanks!!

Gábor Hojtsy’s picture

Status: Fixed » Needs work
Issue tags: +SprintWeekend2015Queue
subhojit777’s picture

Assigned: Unassigned » subhojit777
Gábor Hojtsy’s picture

Issue tags: +SprintWeekend2015
DevElCuy’s picture

Issue tags: -SprintWeekend2015Queue
DevElCuy’s picture

Issue tags: +SprintWeekend2015Queue

Removed tag by mistake.

balagan’s picture

FileSize
147.35 KB

The issue reported is still gone with the committed patch. See image.

balagan’s picture

Status: Needs work » Fixed
Gábor Hojtsy’s picture

balagan’s picture

Issue summary: View changes
balagan’s picture

Assigned: subhojit777 » Unassigned

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.