Skip to content

Commit

Permalink
Merge pull request #10 from gethinode/develop
Browse files Browse the repository at this point in the history
Improve range validation
  • Loading branch information
markdumay authored Feb 5, 2024
2 parents 4f665a5 + 80035f2 commit 94a3c35
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions layouts/partials/utilities/IsInvalidArgs.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@
{{ $error = true }}
{{ end }}
{{ else if and (or $def.options.min $def.options.max) (in (slice "int" "float" "float64") $actual) }}
{{ if or (lt $val $def.options.min) (gt $val $def.options.max) }}
{{ warnf "[%s] argument '%s': value '%s' out of range [%d, %d]" $structure (string $key) (string $val) $def.options.min $def.options.max}}
{{ if or
(and $def.options.min (lt $val $def.options.min))
(and $def.options.max (gt $val $def.options.max))
}}
{{ $min := (string (or $def.options.min "-")) }}
{{ $max := (string (or $def.options.max "-")) }}
{{ warnf "[%s] argument '%s': value '%s' out of range [%s, %s]" $structure (string $key) (string $val) $min $max }}
{{ $error = true }}
{{ end }}
{{ end }}
Expand Down Expand Up @@ -139,4 +144,10 @@
{{ end }}
{{ end }}

{{ if $error }}
{{ $ref := page.RelPermalink }}
{{ with page.File }}{{ $ref = .Filename }}{{ end }}
{{- errorf "[%s] invalid arguments: %s" $structure $ref -}}
{{ end }}

{{ return $error }}

0 comments on commit 94a3c35

Please sign in to comment.