Ensure no empty strings are fed to TranslatableMarkup

Created on 20 September 2015, about 9 years ago
Updated 18 September 2024, 2 months ago

Follow-up to #2570285: Make sure TranslatableMarkup accepts string values only β†’

Follow-up to #2557113: Make t() return a TranslationWrapper object to remove reliance on a static, unpredictable safe list β†’

Problem/Motivation

Empty strings are not valid input for the TranslatableMarkup constructor.

Proposed solution

Fail when input doesn't make sense. Test for empty strings before creating new TranslatableMarkup objects, and leave them as plain strings if they are empty.

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component
Language systemΒ  β†’

Last updated about 5 hours ago

  • Maintained by
  • πŸ‡©πŸ‡ͺGermany @sun
Created by

πŸ‡§πŸ‡ͺBelgium mr.baileys πŸ‡§πŸ‡ͺ (Ghent)

Live updates comments and jobs are added and updated live.
  • Runtime assertion

    It deals with the addition of an assert() statement(s) to the code, and/or contains a test patch where one is failing indicating a need to change code or the documentation the statement was based on.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Could the issue summary be updated for what's needed here? We looking to throw another exception if empty?

  • πŸ‡΅πŸ‡ΉPortugal adaragao

    I'm getting a InvalidArgumentException: $string ("") must be a string. in Drupal\Core\StringTranslation\TranslatableMarkup->__construct() (line 132 of /opt/drupal/web/core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php).

    And I was hoping to go around it with patch #13, but it doesn't work on Drupal 10.3.2.

  • πŸ‡«πŸ‡·France dqd London | N.Y.C | Paris | Hamburg | Berlin

    Cannot access offset can be symptom-ish for empty string - however I wonder if this is related:

    Cannot access offset of type Drupal\Core\StringTranslation\TranslatableMarkup in isset or empty in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 45 of core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php

    When trying to enter admin/structure/types/manage/article/fields/add-field

    Or if this would be another/new issue.

Production build 0.71.5 2024