diff --git a/src/template.sh b/src/template.sh index e2f072c..0a34a50 100755 --- a/src/template.sh +++ b/src/template.sh @@ -27,26 +27,24 @@ function render() { # recursion is currently unsupported here, i feel like it may break things? if [[ "$template" == *'{{#'* && "$3" != true ]]; then local subtemplate= - while read key; do + while read key; do # below check prevents the loop loading itself as a template. # this is possibly not enough to prevent all recursions, but # i see it as a last-ditch measure. so it'll do here. - local i - local IFS='' - - _old_tplfile="$tplfile" - _template_find_absolute_path "$key" - if [[ "$(realpath "$tplfile")" == "$_old_tplfile" ]]; then + if [[ "$file" == "$tplfile" ]]; then subtemplate+="s${_tpl_ctrl}\{\{\#$key\}\}${_tpl_ctrl}I cowardly refuse to endlessly recurse\!${_tpl_ctrl}g;" - continue + # elif [[ -f "$key" ]]; then + else + local i + local IFS='' + + _template_find_absolute_path "$key" + local input="$(tr -d "${_tpl_ctrl}${_tpl_newline}" < "$tplfile" | sed 's/\&/�UwU�/g')" + garbage+="$input"$'\n' + input="$(tr $'\n' "${_tpl_newline}" <<< "$input")" # for another hack + subtemplate+="s${_tpl_ctrl}\{\{\#$key\}\}${_tpl_ctrl}${input}${_tpl_ctrl};" + _template_find_special_uri "$(cat "$tplfile")" fi - # don't even try to include files below httpsh's root - [[ "$(realpath "$tplfile")" != "$(dirname "$(realpath "${cfg[namespace]}")")"* ]] && continue - local input="$(tr -d "${_tpl_ctrl}${_tpl_newline}" < "$tplfile" | sed 's/\&/�UwU�/g')" - garbage+="$input"$'\n' - input="$(tr $'\n' "${_tpl_newline}" <<< "$input")" # for another hack - subtemplate+="s${_tpl_ctrl}\{\{\#$key\}\}${_tpl_ctrl}${input}${_tpl_ctrl};" - _template_find_special_uri "$(cat "$tplfile")" done <<< "$(grep -Poh '{{#\K(.*?)(?=}})' <<< "$template")" buf+="${subtemplate}" @@ -140,10 +138,8 @@ function render() { # # _template_find_absolute_path(name) -> $tplfile _template_find_absolute_path() { - if [[ "$1" == /dev/stdin || "$1" == "/dev/fd/"* ]]; then + if [[ ! "${template_relative_paths}" || "$1" == /dev/stdin || "$1" == "/dev/fd/"* ]]; then tplfile="$1" - elif [[ ! "${template_relative_paths}" ]]; then - tplfile="${cfg[namespace]}/$1" else for (( i=0; i<${#template_relative_paths[@]}; i++ )); do if [[ -f "${template_relative_paths[i]}/$1" ]]; then diff --git a/src/version.sh b/src/version.sh index c290b98..fd70d1b 100644 --- a/src/version.sh +++ b/src/version.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -HTTPSH_VERSION=0.97.2 +HTTPSH_VERSION=0.97.1