diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-11 23:10:28 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-11 23:10:28 +0300 |
| commit | 4c641b00e5f7910afcfd68af6fa149003ce07050 (patch) | |
| tree | 6cc957415da04a12198ba3a2966aa92366f24397 /src/lib/template.source.sh | |
| parent | 7efb6b5e213a7c19b66da1592898c5627f139c17 (diff) | |
fm0 deduplicate escape wrappers
Diffstat (limited to 'src/lib/template.source.sh')
| -rw-r--r-- | src/lib/template.source.sh | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/src/lib/template.source.sh b/src/lib/template.source.sh index 90e0ebd..0f038e4 100644 --- a/src/lib/template.source.sh +++ b/src/lib/template.source.sh @@ -1,13 +1,9 @@ _html_escape() { - local text="$1"; shift - - text=${text//&/\&} - text=${text//</\<} - text=${text//>/\>} - text=${text//\"/\"} - text=${text//\'/\'} + local -r text="$1"; shift + local escaped_text - printf '%s\n' "$text" + html_escape_to escaped_text "$text" + printf '%s\n' "$escaped_text" } html_escape_to() { @@ -24,16 +20,11 @@ html_escape_to() { } _css_string_escape() { - local text="$1"; shift - - text=${text//\\/\\\\} - text=${text//&/\\000026} - text=${text//</\\00003c} - text=${text//>/\\00003e} - text=${text//\"/\\000022} - text=${text//\'/\\000027} + local -r text="$1"; shift + local escaped_text - printf '%s\n' "$text" + css_string_escape_to escaped_text "$text" + printf '%s\n' "$escaped_text" } css_string_escape_to() { |
