Follow-up to #2506445: Replace !placeholder with @placeholder in t() and format_string() for non-URLs in tests

Problem/Motivation

LocaleJavascriptTranslationTest was omitted from the scope of #2506445: Replace !placeholder with @placeholder in t() and format_string() for non-URLs in tests includes test coverage for !placeholder use with (it appears) translated string discovery from JavaScript. We need to evaluate this test (and the functionality that it tests) in light of #2506427: [meta] !placeholder causes strings to be escaped and makes the sanitization API harder to understand.

Code from original issue:

+++ b/core/modules/link/src/Tests/LinkFieldTest.php
--- a/core/modules/locale/src/Tests/LocaleJavascriptTranslationTest.php
+++ b/core/modules/locale/src/Tests/LocaleJavascriptTranslationTest.php

+++ b/core/modules/locale/src/Tests/LocaleJavascriptTranslationTest.php
@@ -58,7 +58,7 @@ public function testFileParsing() {
       "Double Quote \"Escaped\" t" => '',
       'Double Quote Concat strings t' => '',

-      'Context !key Args t' => 'Context string',
+      'Context @key Args t' => 'Context string',

       'Context Unquoted t' => 'Context string unquoted',
       'Context Single Quoted t' => 'Context string single quoted',
@@ -73,7 +73,7 @@ public function testFileParsing() {

@@ -73,7 +73,7 @@ public function testFileParsing() {
       "Double Quote plural{$etx}Double Quote @count plural" => '',
       "Double Quote \"Escaped\" plural{$etx}Double Quote \"Escaped\" @count plural" => '',

-      "Context !key Args plural{$etx}Context !key Args @count plural" => 'Context string',
+      "Context @key Args plural{$etx}Context @key Args @count plural" => 'Context string',

       "Context Unquoted plural{$etx}Context Unquoted @count plural" => 'Context string unquoted',

Proposed resolution

  1. Leave the !placeholder in JS alone and alone in these tests
  2. Add test coverage for JS @placeholder
  3. Add test :placeholder to JavaScript and add test coverage for it.
  4. Change these JS instances to @placeholder as that is what they should be (may need it's own meta or mega patch)

Remaining tasks

TBD

User interface changes

None

API changes

Probably none.

CommentFileSizeAuthor
#7 replace_placeholder-2567727-7.patch2.66 KBsutharsan

Comments

Sutharsan created an issue. See original summary.

xjm’s picture

Thanks @Sutharsan!

Let's split this into two issues please, one for the locale/JS thing and one for the views thing. The unit test will be covered by the patch that actually deprecates or removes the placeholder once we decide which of those we're doing, so no need to have a separate issue for it.

sutharsan’s picture

Title: Folow-up Replace !placeholder with @placeholder in t() for non-URLs in tests » Add test for JavaScript !placeholder equivalent
Issue summary: View changes
sutharsan’s picture

Issue splitted.

xjm’s picture

Title: Add test for JavaScript !placeholder equivalent » LocaleJavascriptTranslationTest has test coverage for !placeholders in JavaScript
Issue summary: View changes
Priority: Normal » Major
sutharsan’s picture

Issue summary: View changes
sutharsan’s picture

Status: Active » Needs review
StatusFileSize
new2.66 KB

Lets start with getting this test working...

sutharsan’s picture

But that made me realize that we overlooked (did not look at) the placehoders in JavaScript. Our Drupal.formatString() still uses '@', '!' and '%'. Just removing the test for '!' is not enough. If we want a ':' placeholder for url's in JS too, we need a test for that too.

dawehner’s picture

As long the other issue is not done yet I would actually suggest to ADD test coverage for @placeholder and keep the existing one for !. This way this issue can be committed without
being blocked on the other one.

sutharsan’s picture

::testFileParsing() is about finding of translatable strings when parsing a JS file. Not about placeholder replacement, not even about finding placeholders. It only checks if a string and its context is found.

To me the usage of '@' or '!' in the placeholder of this test is merely an example and documenting that we have this kind of placeholder. IMHO there is no need that this issue should be blocked by placeholder replacement issue (or vice versa).

dawehner’s picture

Well you still get rid of all the !placeholder cases ... and by that we loose a tiny little bit of test coverage. ... Maybe its just me.

joelpittet’s picture

@Sutharsan and @dawehner I think you are both saying the same thing.

We need to:

  1. Leave the !placeholder in JS alone and alone in these tests
  2. Add test coverage for JS @placeholder
  3. Add test :placeholder to JavaScript and add test coverage for it.
  4. Change these JS instances to @placeholder as that is what they should be (may need it's own meta or mega patch)

Does that work for you both or do you disagree with these steps forward?

dawehner’s picture

@joelpittet Agreed on you

joelpittet’s picture

Issue summary: View changes

Added steps to the Issue summary.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
catch’s picture

Component: base system » locale.module
Status: Needs review » Needs work
Issue tags: -SafeMarkup

The test has moved (core/modules/locale/tests/src/Functional/LocaleJavascriptTranslationTest.php), but this is still valid. Needs a new patch based on #13.

catch’s picture

Title: LocaleJavascriptTranslationTest has test coverage for !placeholders in JavaScript » LocaleJavascriptTranslationTest needs test coverage for @placeholders in JavaScript

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.