Skip to content

uppercase-lowecase issues in the path on windows #314

@fejesd

Description

@fejesd

I'm not sure about the reason, but I get the following error when I attempt to open the web page on windows:

2020-06-18 14:41:32,469 [tornado.application.ERROR] Uncaught exception GET /index.html (127.0.0.1)
HTTPServerRequest(protocol='http', host='127.0.0.1:5000', method='GET', uri='/index.html', version='HTTP/1.1', remote_ip='127.0.0.1')
Traceback (most recent call last):
  File "E:\devel\script-server-sandbox\tornado\web.py", line 1703, in _execute
    result = await result
  File "E:\devel\script-server-sandbox\tornado\web.py", line 2581, in get
    self.absolute_path = self.validate_absolute_path(self.root, absolute_path)
  File "src\web\server.py", line 126, in wrapper
    return func(self, *args, **kwargs)
  File "src\web\server.py", line 608, in validate_absolute_path
    relative_path = file_utils.relative_path(absolute_path, root)
  File "src\utils\file_utils.py", line 150, in relative_path
    raise ValueError(path + ' is not subpath of ' + parent_path)
ValueError: e:\devel\script-server-sandbox\web\index.html is not subpath of E:\devel\script-server-sandbox\web
2020-06-18 14:41:32,481 [tornado.access.ERROR] 500 GET /index.html (127.0.0.1) 12.97ms

This code has fixed the issue for me, but maybe it is not the best approach:

--- a/src/utils/file_utils.py
+++ b/src/utils/file_utils.py
@@ -141,6 +141,10 @@ def last_modification(folder_paths):
 def relative_path(path, parent_path):
     path = normalize_path(path)
     parent_path = normalize_path(parent_path)
+
+    if os.name == 'nt':
+        path = path.capitalize()
+        parent_path = parent_path.capitalize()

     if not path.startswith(parent_path):
         raise ValueError(path + ' is not subpath of ' + parent_path)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions