all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH pve-common v3] fix #7077: schema: validate length before format and pattern
@ 2026-09-21 13:56 Arthur Bied-Charreton
  0 siblings, 0 replies; only message in thread
From: Arthur Bied-Charreton @ 2026-09-21 13:56 UTC (permalink / raw)
  To: pve-devel

The JSON schema validation first checked input against the registered
format function and pattern, and only then against min and max length.

This caused length constraints when they were implicit in custom format
verification functions or regex patterns, which resulted in generic
format violation error messages instead of the more specific length
violation.

Change the validation order to check length constraints before
registered formats and patterns. This is functionally equivalent, and
comes with the UX advantage of providing more precise error messages in
a lot of cases.

Link: https://bugzilla.proxmox.com/show_bug.cgi?id=7077
Signed-off-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
---
Changes since v2: rebase onto master

 src/PVE/JSONSchema.pm | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index 34f2949..ec2072a 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -1627,31 +1627,31 @@ sub check_prop {
             return;
         }
 
-        if (my $format = $schema->{format}) {
-            eval { check_format($format, $value, $path); };
-            if ($@) {
-                add_error($errors, $path, "invalid format - $@");
+        if (defined(my $max = $schema->{maxLength})) {
+            if (length($value) > $max) {
+                add_error($errors, $path, "value may only be $max characters long");
                 return;
             }
         }
 
-        if (my $pattern = $schema->{pattern}) {
-            if ($value !~ m/^$pattern\z/) {
-                add_error($errors, $path, "value does not match the regex pattern");
+        if (defined(my $min = $schema->{minLength})) {
+            if (length($value) < $min) {
+                add_error($errors, $path, "value must be at least $min characters long");
                 return;
             }
         }
 
-        if (defined(my $max = $schema->{maxLength})) {
-            if (length($value) > $max) {
-                add_error($errors, $path, "value may only be $max characters long");
+        if (my $format = $schema->{format}) {
+            eval { check_format($format, $value, $path); };
+            if ($@) {
+                add_error($errors, $path, "invalid format - $@");
                 return;
             }
         }
 
-        if (defined(my $min = $schema->{minLength})) {
-            if (length($value) < $min) {
-                add_error($errors, $path, "value must be at least $min characters long");
+        if (my $pattern = $schema->{pattern}) {
+            if ($value !~ m/^$pattern\z/) {
+                add_error($errors, $path, "value does not match the regex pattern");
                 return;
             }
         }
-- 
2.47.3




^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-21 13:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-21 13:56 [PATCH pve-common v3] fix #7077: schema: validate length before format and pattern Arthur Bied-Charreton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal