From 0ea76b2d887fbd65da6d920e56ca27b226ef0eb4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Wed, 17 Jun 2026 18:27:29 +0200 Subject: [PATCH] custom POST data parser for large page text -> faster processing --- handlers/60_edit.sh | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/handlers/60_edit.sh b/handlers/60_edit.sh index b55a344..1bef79c 100755 --- a/handlers/60_edit.sh +++ b/handlers/60_edit.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright 2022 - 2023 Paul Hänsch +# Copyright 2022 - 2023, 2026 Paul Hänsch # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -25,6 +25,34 @@ edit_page="${PATH_INFO%\[edit\]}" edit_file="$_DATA/pages/$edit_page/#page.md" [ "$REQUEST_METHOD" = POST ] && edit_action="$(POST action)" +edit_handler_pagetext() { + # Custom POST data parser because cgilite POST is only + # fast for small text + local pagetext="$( + printf %s \\n "${cgilite_post}" \ + | sed -En ' + /^(.*&)?pagetext=([^&]*)(&.*)?$/{ + s;^(.*&)?pagetext=([^&]*)(&.*)?$;\2;; + s;\+; ;g; + + s;%.[08];&0;g; s;%.[19];&1;g; + s;%.[2aA];&2;g; s;%.[3bB];&3;g; + s;%.[4cC];&4;g; s;%.[5dD];&5;g; + s;%.[6eE];&6;g; s;%.[7fF];&7;g; + + s;%[048cC][0-7];&0;g; s;%[048cC][89a-fA-F];&1;g; + s;%[159dD][0-7];&2;g; s;%[159dD][89a-fA-F];&3;g; + s;%[26aAeE][0-7];&4;g; s;%[26aAeE][89a-fA-F];&5;g; + s;%[37bBfF][0-7];&6;g; s;%[37bBfF][89a-fA-F];&7;g; + + s;%[0123].;\\0;g; s;%[4567].;\\1;g; + s;%[89aAbB].;\\2;g; s;%[c-fC-F].;\\3;g; + p; + } + ')" + printf -- "$pagetext" +} + if ! acl_write "$edit_page"; then theme_error 403 return 0 @@ -36,7 +64,7 @@ elif [ "$edit_action" = cancel ]; then elif [ "$edit_action" = update ]; then if mkdir -p -- "${edit_file%/#page.md}" \ && S_LOCK "$edit_file"; then - POST pagetext >"$edit_file" + edit_handler_pagetext >"$edit_file" S_RELEASE "$edit_file" else export ERROR_MSG="Unable to lock page for editing" -- 2.47.3