fix: ensure URL parameter is validated before processing remote JSON

This commit is contained in:
Cell
2025-12-23 18:07:06 +08:00
parent 1039e3280e
commit 4fec1cdaa2
2 changed files with 14 additions and 12 deletions
+13 -11
View File
@@ -2,17 +2,19 @@
{{- $url := .URL -}}
{{- $options := .OPTIONS | default dict -}}
{{- if $url -}}
{{- $cacheKey := print $url (now.Format "2006-01-02") -}}
{{- $options = $options | merge (dict "key" $cacheKey) -}}
{{- with try (resources.GetRemote $url $options) -}}
{{- with .Err -}}
{{- erroridf "error-get-remote-json" "%s" . -}}
{{- else with .Value -}}
{{- $response = .Content | transform.Unmarshal -}}
{{- else -}}
{{- erroridf "error-get-remote-json" "Failed to get remote JSON %q" $url -}}
{{- end -}}
{{- if not $url -}}
{{- erroridf "error-get-remote-json" "URL parameter is required!" -}}
{{- end -}}
{{- $cacheKey := print $url (now.Format "2006-01-02") -}}
{{- $options = $options | merge (dict "key" $cacheKey) -}}
{{- with try (resources.GetRemote $url $options) -}}
{{- with .Err -}}
{{- erroridf "error-get-remote-json" "%s" . -}}
{{- else with .Value -}}
{{- $response = .Content | transform.Unmarshal -}}
{{- else -}}
{{- erroridf "error-get-remote-json" "Failed to get remote JSON %q" $url -}}
{{- end -}}
{{- end -}}
+1 -1
View File
@@ -1,4 +1,4 @@
{{- hugo.Store.Set "version" "v0.4.0-alpha.3-20251223090620-8635841c" -}}
{{- hugo.Store.Set "version" "v0.4.0-alpha.3-20251223100706-1039e328" -}}
{{- .Store.Set "this" dict -}}
{{- partial "init/detection-env.html" . -}}