2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-18 08:27:13 +00:00

fixing bad url handling

This commit is contained in:
2025-02-06 00:09:42 +00:00
parent f757d7632c
commit ea77d4f3e4
2 changed files with 21 additions and 12 deletions

View File

@@ -413,6 +413,9 @@ def cavepage(request, karea=None, subpath=None):
cave = caves[0] cave = caves[0]
return rendercave(request, cave, cave.slug()) return rendercave(request, cave, cave.slug())
if len(subpath) > 100: # overlong URL
return redirect(f"/caves")
# HORRIBLE HACK, to be removed.. # HORRIBLE HACK, to be removed..
subpath = subpath.strip("//") subpath = subpath.strip("//")
@@ -420,6 +423,7 @@ def cavepage(request, karea=None, subpath=None):
parts = subpath.strip("/").split("/") parts = subpath.strip("/").split("/")
if len(parts) > 5: if len(parts) > 5:
# recursive loop. break out of it. # recursive loop. break out of it.
print(karea,subpath)
subparts = parts[0].split(".") subparts = parts[0].split(".")
caveid = subparts[0] caveid = subparts[0]
slug = f"{karea}-{caveid}" slug = f"{karea}-{caveid}"
@@ -427,34 +431,39 @@ def cavepage(request, karea=None, subpath=None):
return redirect(f"/{cave.url}") return redirect(f"/{cave.url}")
else: else:
return redirect(f"/caves") return redirect(f"/caves")
# epath = karea + subpath # e.g. 1623 /204 # epath = karea + subpath # e.g. 1623 /204
# return expo.expopage(request, epath) # return expo.expopage(request, epath)
# BUGGER the real problem is the the cave descript has embedded in it images like
# BUGGER the real problem is the the cave description has embedded in it images like
# src="110/entrance.jpeg and since the cave url is now /1623/110/110.html # src="110/entrance.jpeg and since the cave url is now /1623/110/110.html
# the images try to load from /1623/110/110/entrance.jpeg and of course fail. # the images try to load from /1623/110/110/entrance.jpeg and of course fail.
# THIS IS A HORRIBLE HACK # THIS IS A HORRIBLE HACK
if len(parts) == 1: if len(parts) == 1:
# simple filename, no folders in path, # either need to insert caveid OR leave as relative link as we are already "in" /1623/nn/
# either need to insert caveid OR leave as relative link as we are already "in" /1623/nn/ # if we are doing a cave description file
print("SIMPLE", subpath, parts)
subparts = parts[0].split(".") subparts = parts[0].split(".")
caveid = subparts[0] # e.g. 204.htm caveid = subparts[0] # e.g. 204.htm => "204"
k2path = karea +"/"+ caveid + subpath k2path = karea +"/"+ caveid + subpath
return redirect(f"/{k2path}") # infinite loop return redirect(f"/{k2path}") # potential infinite loop
elif len(parts) >2: elif len(parts) >2:
# e.g. i/204.jpg, but that's ok as we are already "in" /1623/nn/ # e.g. i/204.jpg, but that's ok as we are already "in" /1623/nn/
if parts[0] == parts[1]: # double caveid if parts[0] == parts[1]: # double caveid, e.g. /161/161/france.html
epath = karea epath = karea
for i in parts[1:]: for i in parts[1:]:
epath += "/" + i epath += "/" + i
#print(f"{subpath=}\n {epath=}") # print(f"{subpath=}\n {epath=}")
return expo.expopage(request, epath) return expo.expopage(request, epath)
# if either the first two parts are not /caveid/caveid/ # if either the first two parts are not /caveid/caveid/
# or the number of parts == 2, # or the number of parts == 2,
# print(f"2 {subpath=}") # This is the bit that MOST images in descriptions get to.
# simple filename, no folders in path, e.g. href="94_ent_close.jpg"
# inside a cave or entrance description, this "just works" as the href is just
# added to the context of the current page, so there are >> 1 "parts" to the URL.
print(f"2 {subpath=}")
epath = karea + "/" + subpath epath = karea + "/" + subpath
return expo.expopage(request, epath) return expo.expopage(request, epath)

View File

@@ -171,9 +171,9 @@ def expowebpage(request, expowebpath, path):
if path == "" or path == "index.htm": if path == "" or path == "index.htm":
return indexpage(request) return indexpage(request)
if not os.path.isfile(expowebpath / path): if not Path(expowebpath / path).is_file():
# Should not get here if the path has suffix "_edit" # Should not get here if the path has suffix "_edit"
print(f" - 404 error in expowebpage() {path}") print(f" - 404 error in expowebpage() {Path(expowebpath / path)}")
return render(request, "pagenotfound.html", {"path": path}, status=404) return render(request, "pagenotfound.html", {"path": path}, status=404)
# print(f' - {sys_getfilesystemencoding()=}') # print(f' - {sys_getfilesystemencoding()=}')