MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / parsePath

Method parsePath

src/Ui/UiRequest.py:544–562  ·  view source on GitHub ↗
(self, path)

Source from the content-addressed store, hash-verified

542
543 # Return {address: 1Site.., inner_path: /data/users.json} from url path
544 def parsePath(self, path):
545 path = path.replace("\\", "/")
546 path = path.replace("/index.html/", "/") # Base Backward compatibility fix
547 if path.endswith("/"):
548 path = path + "index.html"
549
550 if "../" in path or "./" in path:
551 raise SecurityError("Invalid path")
552
553 match = re.match(r"/media/(?P<address>[A-Za-z0-9]+[A-Za-z0-9\._-]+)(?P<inner_path>/.*|$)", path)
554 if match:
555 path_parts = match.groupdict()
556 path_parts["request_address"] = path_parts["address"] # Original request address (for Merger sites)
557 path_parts["inner_path"] = path_parts["inner_path"].lstrip("/")
558 if not path_parts["inner_path"]:
559 path_parts["inner_path"] = "index.html"
560 return path_parts
561 else:
562 return None
563
564 # Serve a media for site
565 def actionSiteMedia(self, path, header_length=True, header_noscript=False):

Callers 2

actionSiteMediaMethod · 0.95
actionSiteAddPromptMethod · 0.95

Calls 1

SecurityErrorClass · 0.85

Tested by

no test coverage detected