diff --git a/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php
index 1a6e12d01b..2bd4d0e0af 100644
--- a/core/lib/Drupal/Core/Routing/UrlGenerator.php
+++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
@@ -297,28 +297,26 @@ public function generateFromRoute($name, $parameters = [], $options = [], $colle
     }
     // Ensure the resulting path has at most one leading slash, to prevent it
     // becoming an external URL without a protocol like //example.com.
-    if ($path) {
-      if (strpos($path, '//') === 0) {
-        $path = '/' . ltrim($path, '/');
+    if (strpos($path, '//') === 0) {
+      $path = '/' . ltrim($path, '/');
+    }
+    // The contexts base URL is already encoded
+    // (see Symfony\Component\HttpFoundation\Request).
+    $path = str_replace($this->decodedChars[0], $this->decodedChars[1], rawurlencode($path));
+
+    // Drupal paths rarely include dots, so skip this processing if possible.
+    if (strpos($path, '/.') !== FALSE) {
+      // the path segments "." and ".." are interpreted as relative reference when
+      // resolving a URI; see http://tools.ietf.org/html/rfc3986#section-3.3
+      // so we need to encode them as they are not used for this purpose here
+      // otherwise we would generate a URI that, when followed by a user agent
+      // (e.g. browser), does not match this route
+      $path = strtr($path, ['/../' => '/%2E%2E/', '/./' => '/%2E/']);
+      if ('/..' === substr($path, -3)) {
+        $path = substr($path, 0, -2) . '%2E%2E';
       }
-      // The contexts base URL is already encoded
-      // (see Symfony\Component\HttpFoundation\Request).
-      $path = str_replace($this->decodedChars[0], $this->decodedChars[1], rawurlencode($path));
-
-      // Drupal paths rarely include dots, so skip this processing if possible.
-      if (strpos($path, '/.') !== FALSE) {
-        // the path segments "." and ".." are interpreted as relative reference when
-        // resolving a URI; see http://tools.ietf.org/html/rfc3986#section-3.3
-        // so we need to encode them as they are not used for this purpose here
-        // otherwise we would generate a URI that, when followed by a user agent
-        // (e.g. browser), does not match this route
-        $path = strtr($path, ['/../' => '/%2E%2E/', '/./' => '/%2E/']);
-        if ('/..' === substr($path, -3)) {
-          $path = substr($path, 0, -2) . '%2E%2E';
-        }
-        elseif ('/.' === substr($path, -2)) {
-          $path = substr($path, 0, -1) . '%2E';
-        }
+      elseif ('/.' === substr($path, -2)) {
+        $path = substr($path, 0, -1) . '%2E';
       }
     }
 
diff --git a/core/modules/path_alias/src/PathProcessor/AliasPathProcessor.php b/core/modules/path_alias/src/PathProcessor/AliasPathProcessor.php
index 564f8250b5..9959c9373f 100644
--- a/core/modules/path_alias/src/PathProcessor/AliasPathProcessor.php
+++ b/core/modules/path_alias/src/PathProcessor/AliasPathProcessor.php
@@ -51,7 +51,7 @@ public function processOutbound($path, &$options = [], Request $request = NULL,
       // also, to protect against this problem in arbitrary path processors,
       // but it is duplicated here to protect any other URL generation code
       // that might call this method separately.
-      if ($path && strpos($path, '//') === 0) {
+      if (strpos($path, '//') === 0) {
         $path = '/' . ltrim($path, '/');
       }
     }
