From 9db1a8490c1eabbdf06d29fa3e1655bed89caf5c Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 5 Apr 2021 14:49:06 +0100 Subject: [PATCH] fix bug in parsing bad HTML pages e.g.expo 82 --- core/views/expo.py | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/core/views/expo.py b/core/views/expo.py index 0afb7f0..f0b74db 100644 --- a/core/views/expo.py +++ b/core/views/expo.py @@ -23,6 +23,33 @@ This was NOT django.contrib.flatpages which stores HTML in the database, so the Then it was incorporated into troggle directly, rather than being an unnecessary external package. ''' +default_head = ''' + +CUCC Expedition - index + + + + + +

Expo

+

CUCC Expedition

+ +''' + def expofiles_redirect(request, path): '''This is used only when running as a test system without a local copy of /expofiles/ ''' @@ -57,7 +84,7 @@ def expofilesdir(request, dirpath, filepath): return render(request, 'dirdisplay.html', { 'filepath': urlpath, 'fileitems':fileitems, 'diritems': diritems,'settings': settings }) def expowebpage(request, expowebpath, path): - '''Adds memnus and serves an HTML page + '''Adds menus and serves an HTML page ''' if not Path(expowebpath / path).is_file(): return render(request, 'pagenotfound.html', {'path': path}) @@ -69,7 +96,7 @@ def expowebpage(request, expowebpath, path): if m: preheader, headerattrs, head, postheader, bodyattrs, body, postbody = m.groups() else: - return HttpResponse(html + "HTML Parsing failure: Page could not be split into header and body: failed in expowebpage in views.expo.py") + return HttpResponse(default_head + html.decode() + '

HTML Parsing failure:
Page could not be parsed into header and body:
failure detected in expowebpage in views.expo.py

Please edit this :expoweb: page to be in the expected full HTML format by clicking on \'Edit this Page\' in the left hand menu.(.*)", head, re.DOTALL + re.IGNORECASE) if m: title, = m.groups() @@ -212,7 +239,8 @@ def editexpopage(request, path): # if re.search(r"iso-8859-1", html): # body = str(body, "iso-8859-1") else: - return HttpResponse("Page could not be split into header and body") + #return HttpResponse("Page could not be split into header and body") + return HttpResponse(default_head + html.decode() + '

HTML Parsing failure:
Page could not be parsed into header and body:
failure detected in expowebpage in views.expo.py

Please edit this :expoweb: page to be in the expected full HTML format by clicking on \'Edit this Page\' in the left hand menu.(.*)", head, re.DOTALL + re.IGNORECASE)