diff --git a/core/includes/file.inc b/core/includes/file.inc
index 8d2ebbe..b38cf14 100644
--- a/core/includes/file.inc
+++ b/core/includes/file.inc
@@ -323,7 +323,19 @@ function file_create_url($uri) {
     else {
       // If this is not a properly formatted stream, then it is a shipped file.
       // Therefore, return the urlencoded URI with the base URL prepended.
-      return $GLOBALS['base_url'] . '/' . UrlHelper::encodePath($uri);
+      $options = UrlHelper::parse($uri);
+      $path = $GLOBALS['base_url'] . '/' . UrlHelper::encodePath($options['path']);
+      // Append the query.
+      if ($options['query']) {
+        $path .= '?' . UrlHelper::buildQuery($options['query']);
+      }
+
+      // Append fragment.
+      if ($options['fragment']) {
+        $path .= '#' . $options['fragment'];
+      }
+
+      return $path;
     }
   }
   elseif ($scheme == 'http' || $scheme == 'https' || $scheme == 'data') {
diff --git a/core/modules/system/src/Tests/File/UrlRewritingTest.php b/core/modules/system/src/Tests/File/UrlRewritingTest.php
index 2c428ae..8b2f455 100644
--- a/core/modules/system/src/Tests/File/UrlRewritingTest.php
+++ b/core/modules/system/src/Tests/File/UrlRewritingTest.php
@@ -56,6 +56,18 @@ function testShippedFileURL()  {
     $filepath = 'core/misc/favicon.ico';
     $url = file_create_url($filepath);
     $this->assertEqual('/' . base_path() . '/' . $filepath, $url, 'Correctly generated a protocol-relative URL for a shipped file.');
+
+    // Test alteration of file URLs with query strings and/or fragment.
+    \Drupal::state()->delete('file_test.hook_file_url_alter');
+    $filepath = 'core/misc/favicon.ico';
+    $url = file_create_url($filepath . '?foo');
+    $this->assertEqual($GLOBALS['base_url'] . '/' . $filepath . '?foo=', $url, 'Correctly generated url. The query string is present.');
+    $url = file_create_url($filepath . '?foo=bar');
+    $this->assertEqual($GLOBALS['base_url'] . '/' . $filepath . '?foo=bar', $url, 'Correctly generated url. The query string is present.');
+    $url = file_create_url($filepath . '#v1.2');
+    $this->assertEqual($GLOBALS['base_url'] . '/' . $filepath . '#v1.2', $url, 'Correctly generated url. The fragment is present.');
+    $url = file_create_url($filepath . '?foo=bar#v1.2');
+    $this->assertEqual($GLOBALS['base_url'] . '/' . $filepath . '?foo=bar#v1.2', $url, 'Correctly generated url. The query string amd fragment is present.');
   }
 
   /**
