From c15fd72ed0c779b872360a2546ff60767772d8ee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Mon, 19 Jun 2023 15:32:26 +0200 Subject: [PATCH] Squashed 'cgilite/' changes from 8fd595c0..8ce6dce8 8ce6dce8 bugfix: do not accidentally strip white spaces from code spans c4ba9cc2 Include backtick (`) in URL escape handling d61539cd bugfix: prevent endless loop in HEX_DECODE, copy non-hex-digits unchanged git-subtree-dir: cgilite git-subtree-split: 8ce6dce8725f84096aebcf1a4063eaeee754b92a --- cgilite.sh | 7 +++++++ markdown.awk | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cgilite.sh b/cgilite.sh index b51ee8e..76c91b2 100755 --- a/cgilite.sh +++ b/cgilite.sh @@ -85,6 +85,12 @@ HEX_DECODE(){ # will be copied to the output literally while [ "$in" ]; do + [ "$pfx" ] || case $in in + [0-9a-fA-F][0-9a-fA-F]*):;; + ?*) out="${out}${in%%"${in#?}"}" + in="${in#?}"; continue;; + esac + case $in in "$pfx"[0-9a-fA-F][0-9a-fA-F]*) in="${in#${pfx}}";; \\*) in="${in#?}"; out="${out}\\\\"; continue;; @@ -307,6 +313,7 @@ URL(){ \&*) out="${out}%26"; str="${str#?}";; \"*) out="${out}%22"; str="${str#?}";; \'*) out="${out}%27"; str="${str#?}";; + \`*) out="${out}%60"; str="${str#?}";; \?*) out="${out}%3F"; str="${str#?}";; \#*) out="${out}%23"; str="${str#?}";; \[*) out="${out}%5B"; str="${str#?}";; diff --git a/markdown.awk b/markdown.awk index af3d722..3fa248d 100755 --- a/markdown.awk +++ b/markdown.awk @@ -93,6 +93,7 @@ function URL ( text ) { gsub( /&/, "%26", text ); gsub( /"/, "%22", text ); gsub( /'/, "%27", text ); + gsub( /`/, "%60", text ); gsub( /\?/, "%3F", text ); gsub( /#/, "%23", text ); gsub( /\[/, "%5B", text ); @@ -130,7 +131,7 @@ function inline( line, LOCAL, len, code, href, guard ) { code = substr( line, len + 1, match( substr(line, len + 1), guard ) - 1) len = 2 * length(guard) + length(code) # strip single surrounding white spaces - code = gensub( / (.*) /, "\\1", "1" , code) + code = gensub( /^ | $/, "", "g" , code) # escape HTML within code span gsub( /&/, "\\&", code ); gsub( //, "\\>", code ); return "" code "" inline( substr( line, len + 1 ) ) -- 2.39.2