From: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-common v3] fix #7077: schema: validate length before format and pattern
Date: Mon, 21 Sep 2026 15:56:32 +0200 [thread overview]
Message-ID: <20260921135701.475036-1-a.bied-charreton@proxmox.com> (raw)
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
reply other threads:[~2026-09-21 13:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260921135701.475036-1-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