summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2022-08-13 21:13:40 -0500
committerCase Duckworth2022-08-13 21:13:40 -0500
commit4e310f34d8a6600c7a50b52fc671225f5d5af854 (patch)
tree954b79aa87faf1b9d20b057ff7a5bc871b53fe4c
parentEscape .. escapes (diff)
downloadht-4e310f34d8a6600c7a50b52fc671225f5d5af854.tar.gz
ht-4e310f34d8a6600c7a50b52fc671225f5d5af854.zip
Correctly escape everything from heredoc
-rwxr-xr-xht.awk20
1 files changed, 7 insertions, 13 deletions
diff --git a/ht.awk b/ht.awk index 80eb464..2e8c5d2 100755 --- a/ht.awk +++ b/ht.awk
@@ -14,19 +14,6 @@ BEGIN {
14 ATTR = DEFATTR 14 ATTR = DEFATTR
15} 15}
16 16
17# Sure, let's do templating! This makes it less... weird.
18# This has to come before raw handling so that code doesn't get expanded in raw sections.
19/\$/ {
20 if (RAW) {
21 gsub(/\$/, "\\\\&", $0)
22 } else {
23 # XXX: This is probably the dumbest way to do it.
24 gsub(/\$\$/, "$\a", $0)
25 gsub(/\$[^\a]/, "\\\\&", $0)
26 gsub(/\$\a/, "$", $0)
27 }
28}
29
30# Handle raw sections 17# Handle raw sections
31$0 ~ CONFIG["raw_delim"] { 18$0 ~ CONFIG["raw_delim"] {
32 RAW = ! RAW 19 RAW = ! RAW
@@ -45,6 +32,7 @@ $0 ~ CONFIG["raw_delim"] {
45} 32}
46 33
47RAW { 34RAW {
35 gsub(/[\\\$]/, "\\\\&", $0)
48 bufpush(html_escape($0)) 36 bufpush(html_escape($0))
49 next 37 next
50} 38}
@@ -70,6 +58,7 @@ $0 ~ ("^" COMMENT_DELIM) {
70 } else { 58 } else {
71 sep = "\n" 59 sep = "\n"
72 } 60 }
61 gsub(/\\/, "\\\\", $0)
73 $0 = html_escape($0) 62 $0 = html_escape($0)
74 # Loop through BLOCK_TYPES 63 # Loop through BLOCK_TYPES
75 for (bt in BLOCK_TYPES) { 64 for (bt in BLOCK_TYPES) {
@@ -141,6 +130,11 @@ $0 ~ ("^" COMMENT_DELIM) {
141 $0 = templ 130 $0 = templ
142 } 131 }
143 } 132 }
133 # Escape stuff for the shell -- allow $$ to expand
134 gsub(/\$\$/, "$\a", $0)
135 gsub(/\$[^\a]/, "\\\\&", $0)
136 gsub(/\$\a/, "$", $0)
137 gsub(/`/, "\\`", $0)
144 # Push to buffer 138 # Push to buffer
145 bufpush($0, sep) 139 bufpush($0, sep)
146} 140}