Follow-up to #2514044: Do not use SafeMarkup::format in exceptions
Problem/Motivation
We are escaping exception messages when we are creating exceptions. If the exception message is never displayed or used this wastes valuable time escaping and consume static memory in SafeMarkup::set().
Amusingly all exception messages are escaped again in Error::decodeException()
so if it is displayed then there is double escaping. (Hence this issue having a bug status).
Proposed resolution
Use sprintf()/concatentation/magic strings to munge strings together when creating exceptions.
// In \Drupal\Component\Utility\UrlHelper
throw new \InvalidArgumentException(SafeMarkup::format('A path was passed when a fully qualified domain was expected.'));
// Should be
throw new \InvalidArgumentException('A path was passed when a fully qualified domain was expected.');
// In \Drupal\Core\Url
throw new \InvalidArgumentException(SafeMarkup::format("The user-entered string @user_input must begin with a '/', '?', or '#'.", ['@user_input' => $user_input]));
// Should be
throw new \InvalidArgumentException("The user-entered string $user_input must begin with a '/', '?', or '#'.");
Remaining tasks
Fix core
User interface changes
None
API changes
None
Data model changes
None