]> git.plutz.net Git - shellwiki/commitdiff
custom POST data parser for large page text -> faster processing
authorPaul Hänsch <paul@plutz.net>
Wed, 17 Jun 2026 16:27:29 +0000 (18:27 +0200)
committerPaul Hänsch <paul@plutz.net>
Wed, 17 Jun 2026 16:27:29 +0000 (18:27 +0200)
handlers/60_edit.sh

index b55a3440bf91ba77e27ccca3aab0e7b9e28b2642..1bef79c24717f0d0d2d9ed01df2a8326a2477f76 100755 (executable)
@@ -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"