diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2025-02-06 00:09:42 +0000 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2025-02-06 00:09:42 +0000 |
commit | ea77d4f3e451860276765f8d879375903d89e8d5 (patch) | |
tree | 71c2bde4f81d5204122e8ca85e54c9bc08d52af4 | |
parent | f757d7632c24ba251c7042c16f2d4fa77ba2493f (diff) | |
download | troggle-ea77d4f3e451860276765f8d879375903d89e8d5.tar.gz troggle-ea77d4f3e451860276765f8d879375903d89e8d5.tar.bz2 troggle-ea77d4f3e451860276765f8d879375903d89e8d5.zip |
fixing bad url handling
-rw-r--r-- | core/views/caves.py | 29 | ||||
-rw-r--r-- | core/views/expo.py | 4 |
2 files changed, 21 insertions, 12 deletions
diff --git a/core/views/caves.py b/core/views/caves.py index d469a9d..75971bb 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -413,6 +413,9 @@ def cavepage(request, karea=None, subpath=None): cave = caves[0] return rendercave(request, cave, cave.slug()) + if len(subpath) > 100: # overlong URL + return redirect(f"/caves") + # HORRIBLE HACK, to be removed.. subpath = subpath.strip("//") @@ -420,6 +423,7 @@ def cavepage(request, karea=None, subpath=None): parts = subpath.strip("/").split("/") if len(parts) > 5: # recursive loop. break out of it. + print(karea,subpath) subparts = parts[0].split(".") caveid = subparts[0] slug = f"{karea}-{caveid}" @@ -427,34 +431,39 @@ def cavepage(request, karea=None, subpath=None): return redirect(f"/{cave.url}") else: return redirect(f"/caves") - - + # epath = karea + subpath # e.g. 1623 /204 # 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 # the images try to load from /1623/110/110/entrance.jpeg and of course fail. # THIS IS A HORRIBLE HACK 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(".") - caveid = subparts[0] # e.g. 204.htm + caveid = subparts[0] # e.g. 204.htm => "204" k2path = karea +"/"+ caveid + subpath - return redirect(f"/{k2path}") # infinite loop + return redirect(f"/{k2path}") # potential infinite loop elif len(parts) >2: # 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 for i in parts[1:]: epath += "/" + i - #print(f"{subpath=}\n {epath=}") + # print(f"{subpath=}\n {epath=}") return expo.expopage(request, epath) # if either the first two parts are not /caveid/caveid/ # 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 return expo.expopage(request, epath) diff --git a/core/views/expo.py b/core/views/expo.py index ac5c522..d492820 100644 --- a/core/views/expo.py +++ b/core/views/expo.py @@ -171,9 +171,9 @@ def expowebpage(request, expowebpath, path): if path == "" or path == "index.htm": 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" - 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) # print(f' - {sys_getfilesystemencoding()=}') |