diff --git a/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php
index 5103bf2..f233972 100644
--- a/core/lib/Drupal/Core/Routing/UrlGenerator.php
+++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
@@ -54,14 +54,17 @@ class UrlGenerator implements UrlGeneratorInterface {
   /**
    * Overrides characters that will not be percent-encoded in the path segment.
    *
+   * The first two elements are the first two parameters of str_replace().
+   *
    * @see \Symfony\Component\Routing\Generator\UrlGenerator
    */
-  protected $decodedChars = array(
+  protected $decodedChars = [
     // the slash can be used to designate a hierarchical structure and we want allow using it with this meaning
     // some webservers don't allow the slash in encoded form in the path for security reasons anyway
     // see http://stackoverflow.com/questions/4069002/http-400-if-2f-part-of-get-url-in-jboss
-    '%2F' => '/',
-  );
+    ['%2F'], // Map from these encoded characters.
+    ['/'], // Map to these decoded characters.
+  ];
 
   /**
    *  Constructs a new generator object.
@@ -212,7 +215,8 @@ protected function doGenerate(array $variables, array $defaults, array $tokens,
     }
 
     // The contexts base URL is already encoded (see Symfony\Component\HttpFoundation\Request)
-    $url = strtr(rawurlencode($url), $this->decodedChars);
+    list($search_strings, $replacement_strings) = $this->decodedChars;
+    $url = str_replace($search_strings, $replacement_strings, rawurlencode($url));
 
     // Drupal paths rarely include dots, so skip this processing if possible.
     if (strpos($url, '/.') !== FALSE) {
