We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
what have done to static.py?
On last Friday,everything is ok,my static file test works fine.

Today,when I pip install sanic==0.5.1
It raise 404 error.

when I pip install sanic==0.5.0
everything is ok again.

seems like the code blow has some problem?
if not file_path.startswith(root_path):
            raise FileNotFound('File not found',
                               path=file_or_directory,
                               relative_url=file_uri)

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `sanic/static.py`
Content:
```
1 from mimetypes import guess_type
2 from os import path
3 from re import sub
4 from time import strftime, gmtime
5 from urllib.parse import unquote
6 
7 from aiofiles.os import stat
8 
9 from sanic.exceptions import (
10     ContentRangeError,
11     FileNotFound,
12     HeaderNotFound,
13     InvalidUsage,
14 )
15 from sanic.handlers import ContentRangeHandler
16 from sanic.response import file, HTTPResponse
17 
18 
19 def register(app, uri, file_or_directory, pattern,
20              use_modified_since, use_content_range):
21     # TODO: Though sanic is not a file server, I feel like we should at least
22     #       make a good effort here.  Modified-since is nice, but we could
23     #       also look into etags, expires, and caching
24     """
25     Register a static directory handler with Sanic by adding a route to the
26     router and registering a handler.
27 
28     :param app: Sanic
29     :param file_or_directory: File or directory path to serve from
30     :param uri: URL to serve from
31     :param pattern: regular expression used to match files in the URL
32     :param use_modified_since: If true, send file modified time, and return
33                                not modified if the browser's matches the
34                                server's
35     :param use_content_range: If true, process header for range requests
36                               and sends the file part that is requested
37     """
38     # If we're not trying to match a file directly,
39     # serve from the folder
40     if not path.isfile(file_or_directory):
41         uri += '<file_uri:' + pattern + '>'
42 
43     async def _handler(request, file_uri=None):
44         # Using this to determine if the URL is trying to break out of the path
45         # served.  os.path.realpath seems to be very slow
46         if file_uri and '../' in file_uri:
47             raise InvalidUsage("Invalid URL")
48         # Merge served directory and requested file if provided
49         # Strip all / that in the beginning of the URL to help prevent python
50         # from herping a derp and treating the uri as an absolute path
51         root_path = file_path = file_or_directory
52         if file_uri:
53             file_path = path.join(
54                 file_or_directory, sub('^[/]*', '', file_uri))
55 
56         # URL decode the path sent by the browser otherwise we won't be able to
57         # match filenames which got encoded (filenames with spaces etc)
58         file_path = path.abspath(unquote(file_path))
59         if not file_path.startswith(root_path):
60             raise FileNotFound('File not found',
61                                path=file_or_directory,
62                                relative_url=file_uri)
63         try:
64             headers = {}
65             # Check if the client has been sent this file before
66             # and it has not been modified since
67             stats = None
68             if use_modified_since:
69                 stats = await stat(file_path)
70                 modified_since = strftime(
71                     '%a, %d %b %Y %H:%M:%S GMT', gmtime(stats.st_mtime))
72                 if request.headers.get('If-Modified-Since') == modified_since:
73                     return HTTPResponse(status=304)
74                 headers['Last-Modified'] = modified_since
75             _range = None
76             if use_content_range:
77                 _range = None
78                 if not stats:
79                     stats = await stat(file_path)
80                 headers['Accept-Ranges'] = 'bytes'
81                 headers['Content-Length'] = str(stats.st_size)
82                 if request.method != 'HEAD':
83                     try:
84                         _range = ContentRangeHandler(request, stats)
85                     except HeaderNotFound:
86                         pass
87                     else:
88                         del headers['Content-Length']
89                         for key, value in _range.headers.items():
90                             headers[key] = value
91             if request.method == 'HEAD':
92                 return HTTPResponse(
93                     headers=headers,
94                     content_type=guess_type(file_path)[0] or 'text/plain')
95             else:
96                 return await file(file_path, headers=headers, _range=_range)
97         except ContentRangeError:
98             raise
99         except Exception:
100             raise FileNotFound('File not found',
101                                path=file_or_directory,
102                                relative_url=file_uri)
103 
104     app.route(uri, methods=['GET', 'HEAD'])(_handler)
105
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/sanic/static.py b/sanic/static.py
--- a/sanic/static.py
+++ b/sanic/static.py
@@ -56,7 +56,7 @@
         # URL decode the path sent by the browser otherwise we won't be able to
         # match filenames which got encoded (filenames with spaces etc)
         file_path = path.abspath(unquote(file_path))
-        if not file_path.startswith(root_path):
+        if not file_path.startswith(path.abspath(unquote(root_path))):
             raise FileNotFound('File not found',
                                path=file_or_directory,
                                relative_url=file_uri)

{"golden_diff": "diff --git a/sanic/static.py b/sanic/static.py\n--- a/sanic/static.py\n+++ b/sanic/static.py\n@@ -56,7 +56,7 @@\n         # URL decode the path sent by the browser otherwise we won't be able to\n         # match filenames which got encoded (filenames with spaces etc)\n         file_path = path.abspath(unquote(file_path))\n-        if not file_path.startswith(root_path):\n+        if not file_path.startswith(path.abspath(unquote(root_path))):\n             raise FileNotFound('File not found',\n                                path=file_or_directory,\n                                relative_url=file_uri)\n", "issue": "what have done to static.py?\nOn last Friday,everything is ok,my static file test works fine.\r\n\r\nToday,when I pip install sanic==0.5.1\r\nIt raise 404 error.\r\n\r\nwhen I pip install sanic==0.5.0\r\neverything is ok again.\r\n\r\nseems like the code blow has some problem?\r\nif not file_path.startswith(root_path):\r\n            raise FileNotFound('File not found',\r\n                               path=file_or_directory,\r\n                               relative_url=file_uri)\n", "before_files": [{"content": "from mimetypes import guess_type\nfrom os import path\nfrom re import sub\nfrom time import strftime, gmtime\nfrom urllib.parse import unquote\n\nfrom aiofiles.os import stat\n\nfrom sanic.exceptions import (\n    ContentRangeError,\n    FileNotFound,\n    HeaderNotFound,\n    InvalidUsage,\n)\nfrom sanic.handlers import ContentRangeHandler\nfrom sanic.response import file, HTTPResponse\n\n\ndef register(app, uri, file_or_directory, pattern,\n             use_modified_since, use_content_range):\n    # TODO: Though sanic is not a file server, I feel like we should at least\n    #       make a good effort here.  Modified-since is nice, but we could\n    #       also look into etags, expires, and caching\n    \"\"\"\n    Register a static directory handler with Sanic by adding a route to the\n    router and registering a handler.\n\n    :param app: Sanic\n    :param file_or_directory: File or directory path to serve from\n    :param uri: URL to serve from\n    :param pattern: regular expression used to match files in the URL\n    :param use_modified_since: If true, send file modified time, and return\n                               not modified if the browser's matches the\n                               server's\n    :param use_content_range: If true, process header for range requests\n                              and sends the file part that is requested\n    \"\"\"\n    # If we're not trying to match a file directly,\n    # serve from the folder\n    if not path.isfile(file_or_directory):\n        uri += '<file_uri:' + pattern + '>'\n\n    async def _handler(request, file_uri=None):\n        # Using this to determine if the URL is trying to break out of the path\n        # served.  os.path.realpath seems to be very slow\n        if file_uri and '../' in file_uri:\n            raise InvalidUsage(\"Invalid URL\")\n        # Merge served directory and requested file if provided\n        # Strip all / that in the beginning of the URL to help prevent python\n        # from herping a derp and treating the uri as an absolute path\n        root_path = file_path = file_or_directory\n        if file_uri:\n            file_path = path.join(\n                file_or_directory, sub('^[/]*', '', file_uri))\n\n        # URL decode the path sent by the browser otherwise we won't be able to\n        # match filenames which got encoded (filenames with spaces etc)\n        file_path = path.abspath(unquote(file_path))\n        if not file_path.startswith(root_path):\n            raise FileNotFound('File not found',\n                               path=file_or_directory,\n                               relative_url=file_uri)\n        try:\n            headers = {}\n            # Check if the client has been sent this file before\n            # and it has not been modified since\n            stats = None\n            if use_modified_since:\n                stats = await stat(file_path)\n                modified_since = strftime(\n                    '%a, %d %b %Y %H:%M:%S GMT', gmtime(stats.st_mtime))\n                if request.headers.get('If-Modified-Since') == modified_since:\n                    return HTTPResponse(status=304)\n                headers['Last-Modified'] = modified_since\n            _range = None\n            if use_content_range:\n                _range = None\n                if not stats:\n                    stats = await stat(file_path)\n                headers['Accept-Ranges'] = 'bytes'\n                headers['Content-Length'] = str(stats.st_size)\n                if request.method != 'HEAD':\n                    try:\n                        _range = ContentRangeHandler(request, stats)\n                    except HeaderNotFound:\n                        pass\n                    else:\n                        del headers['Content-Length']\n                        for key, value in _range.headers.items():\n                            headers[key] = value\n            if request.method == 'HEAD':\n                return HTTPResponse(\n                    headers=headers,\n                    content_type=guess_type(file_path)[0] or 'text/plain')\n            else:\n                return await file(file_path, headers=headers, _range=_range)\n        except ContentRangeError:\n            raise\n        except Exception:\n            raise FileNotFound('File not found',\n                               path=file_or_directory,\n                               relative_url=file_uri)\n\n    app.route(uri, methods=['GET', 'HEAD'])(_handler)\n", "path": "sanic/static.py"}], "after_files": [{"content": "from mimetypes import guess_type\nfrom os import path\nfrom re import sub\nfrom time import strftime, gmtime\nfrom urllib.parse import unquote\n\nfrom aiofiles.os import stat\n\nfrom sanic.exceptions import (\n    ContentRangeError,\n    FileNotFound,\n    HeaderNotFound,\n    InvalidUsage,\n)\nfrom sanic.handlers import ContentRangeHandler\nfrom sanic.response import file, HTTPResponse\n\n\ndef register(app, uri, file_or_directory, pattern,\n             use_modified_since, use_content_range):\n    # TODO: Though sanic is not a file server, I feel like we should at least\n    #       make a good effort here.  Modified-since is nice, but we could\n    #       also look into etags, expires, and caching\n    \"\"\"\n    Register a static directory handler with Sanic by adding a route to the\n    router and registering a handler.\n\n    :param app: Sanic\n    :param file_or_directory: File or directory path to serve from\n    :param uri: URL to serve from\n    :param pattern: regular expression used to match files in the URL\n    :param use_modified_since: If true, send file modified time, and return\n                               not modified if the browser's matches the\n                               server's\n    :param use_content_range: If true, process header for range requests\n                              and sends the file part that is requested\n    \"\"\"\n    # If we're not trying to match a file directly,\n    # serve from the folder\n    if not path.isfile(file_or_directory):\n        uri += '<file_uri:' + pattern + '>'\n\n    async def _handler(request, file_uri=None):\n        # Using this to determine if the URL is trying to break out of the path\n        # served.  os.path.realpath seems to be very slow\n        if file_uri and '../' in file_uri:\n            raise InvalidUsage(\"Invalid URL\")\n        # Merge served directory and requested file if provided\n        # Strip all / that in the beginning of the URL to help prevent python\n        # from herping a derp and treating the uri as an absolute path\n        root_path = file_path = file_or_directory\n        if file_uri:\n            file_path = path.join(\n                file_or_directory, sub('^[/]*', '', file_uri))\n\n        # URL decode the path sent by the browser otherwise we won't be able to\n        # match filenames which got encoded (filenames with spaces etc)\n        file_path = path.abspath(unquote(file_path))\n        if not file_path.startswith(path.abspath(unquote(root_path))):\n            raise FileNotFound('File not found',\n                               path=file_or_directory,\n                               relative_url=file_uri)\n        try:\n            headers = {}\n            # Check if the client has been sent this file before\n            # and it has not been modified since\n            stats = None\n            if use_modified_since:\n                stats = await stat(file_path)\n                modified_since = strftime(\n                    '%a, %d %b %Y %H:%M:%S GMT', gmtime(stats.st_mtime))\n                if request.headers.get('If-Modified-Since') == modified_since:\n                    return HTTPResponse(status=304)\n                headers['Last-Modified'] = modified_since\n            _range = None\n            if use_content_range:\n                _range = None\n                if not stats:\n                    stats = await stat(file_path)\n                headers['Accept-Ranges'] = 'bytes'\n                headers['Content-Length'] = str(stats.st_size)\n                if request.method != 'HEAD':\n                    try:\n                        _range = ContentRangeHandler(request, stats)\n                    except HeaderNotFound:\n                        pass\n                    else:\n                        del headers['Content-Length']\n                        for key, value in _range.headers.items():\n                            headers[key] = value\n            if request.method == 'HEAD':\n                return HTTPResponse(\n                    headers=headers,\n                    content_type=guess_type(file_path)[0] or 'text/plain')\n            else:\n                return await file(file_path, headers=headers, _range=_range)\n        except ContentRangeError:\n            raise\n        except Exception:\n            raise FileNotFound('File not found',\n                               path=file_or_directory,\n                               relative_url=file_uri)\n\n    app.route(uri, methods=['GET', 'HEAD'])(_handler)\n", "path": "sanic/static.py"}]}