- Issue created by @andyg5000
- Merge request !182Fixes #3545583: Ensure translatable markup is rendered as a string before passing to Stripe → (Open) created by andyg5000
- 🇮🇱Israel jsacksick
I don't think the call to render() is necessary:
TranslatableMarkup uses the ToStringTrait() which implements the magic __toString() method:
/** * Implements the magic __toString() method. */ public function __toString() { try { return (string) $this->render(); } catch (\Exception $e) { // User errors in __toString() methods are considered fatal in the Drupal // error handler. trigger_error(get_class($e) . ' thrown while calling __toString on a ' . static::class . ' object in ' . $e->getFile() . ' on line ' . $e->getLine() . ': ' . $e->getMessage(), E_USER_WARNING); // In case we are using another error handler that did not fatal on the // E_USER_ERROR, we terminate execution. However, for test purposes allow // a return value. return $this->_die(); } }
Btw, looking at the stacktrace, I see that the render() method is actually invoked:
#2 /var/www/html/web/core/lib/Drupal/Component/Utility/ToStringTrait.php(15): Drupal\Core\StringTranslation\TranslatableMarkup->render() #3 /var/www/html/vendor/stripe/stripe-php/lib/Util/Util.php(233): Drupal\Core\StringTranslation\TranslatableMarkup->__toString()
I think you're misinterpreting the error, the error you're seeing seems to be due to a placeholder that can't be properly replaced (likely due to an empty email??)
The stacktrace actually shows that:
#1 /var/www/html/web/core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php(195): Drupal\Component\Render\FormattableMarkup::placeholderFormat()
and then:
#0 /var/www/html/web/core/lib/Drupal/Component/Render/FormattableMarkup.php(202): Drupal\Component\Utility\Html::escape()
Line 202 is:
$args[$key] = Html::escape($value);
So I'm like 99% sure that this is happening due to an empty email. Would you be able to confirm that?
If so, ther right fix would be to pass an empty string instread of NULL.