From: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-common v2 1/1] fix #7077: Change JSON Schema attribute validation order
Date: Fri, 6 Feb 2026 17:12:32 +0100 [thread overview]
Message-ID: <20260206161236.335026-2-a.bied-charreton@proxmox.com> (raw)
In-Reply-To: <20260206161236.335026-1-a.bied-charreton@proxmox.com>
The JSON Schema validation first checks input against the registered
format function, then against the registered pattern, and only then
against {min,max}-length.
This causes length constraints to be poorly reported when they are
implicit in custom format verification code or regex patterns, which
results in generic format violation error messages instead of the
more specific length violation.
Change the validation order to check length constraints before anything
else. This is functionally equivalent, and comes with the UX advantage
of providing more precise error messages in a lot of cases.
Signed-off-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
---
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 0c9bb82..531a52c 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -1463,31 +1463,31 @@ sub check_prop {
} else {
- 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$/) {
- 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$/) {
+ add_error($errors, $path, "value does not match the regex pattern");
return;
}
}
--
2.47.3
next prev parent reply other threads:[~2026-02-06 16:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-06 16:12 [PATCH proxmox, pve-{common,network,storage} v2 0/5] fix #7077: Improve error messages for ID verification Arthur Bied-Charreton
2026-02-06 16:12 ` Arthur Bied-Charreton [this message]
2026-02-06 16:12 ` [PATCH pve-network v2 1/2] fix #7077: Enforce ID format in JSON schema definitions Arthur Bied-Charreton
2026-02-06 16:12 ` [PATCH pve-network v2 2/2] sdn: Remove unneeded registered formats Arthur Bied-Charreton
2026-02-06 16:12 ` [PATCH pve-storage v2 1/1] fix #7077: lvm: Improve ID verification error messages Arthur Bied-Charreton
2026-02-06 16:12 ` [PATCH proxmox v2 1/1] fix #7077: Improve SDN ID validation " Arthur Bied-Charreton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260206161236.335026-2-a.bied-charreton@proxmox.com \
--to=a.bied-charreton@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox