public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: Thomas Lamprecht <t.lamprecht@proxmox.com>,
	Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Subject: Re: [pve-devel] [PATCH stable-7+master manager] ui: vm selector: handle empty string gracefully
Date: Fri, 7 Jul 2023 09:41:52 +0200	[thread overview]
Message-ID: <906a4644-d7fa-3c71-5d51-5d45ffce9dc3@proxmox.com> (raw)
In-Reply-To: <5c9ba76f-e505-822f-237d-b2dcdce347d2@proxmox.com>

Am 06.07.23 um 18:16 schrieb Thomas Lamprecht:
> Am 06/07/2023 um 15:51 schrieb Fiona Ebner:
>> which is passed by the backup job window when using selection mode
>> 'all', would be converted to [""] and wrongly add an entry with VMID
>> 0 because the item "" could not be found in the store.
>>
>> Reported in the community forum:
>> https://forum.proxmox.com/threads/130164/
>>
>> Fixes: 7a5ca76a ("fix #4239: ui: show selected but non-existing vmids in backup edit")
>> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
>> ---
>>  www/manager6/form/VMSelector.js | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/www/manager6/form/VMSelector.js b/www/manager6/form/VMSelector.js
>> index 4c0bba13..bf2c8df7 100644
>> --- a/www/manager6/form/VMSelector.js
>> +++ b/www/manager6/form/VMSelector.js
>> @@ -162,7 +162,7 @@ Ext.define('PVE.form.VMSelector', {
>>      setValue: function(value) {
>>  	let me = this;
>>  	if (!Ext.isArray(value)) {
>> -	    value = value.split(',');
>> +	    value = value === '' ? [] : value.split(',');
> 
> more future proof would be doing it (also) on the call sites, as then future callers

In favor of the "also", because it just feels cleaner to parse the empty
list as an empty array and avoid the invalid '' item in the first place.
And if the future would bring a new usage of the parsed value in
setValue() here, then the above is future-proof ;)

> are also guarded against it, e.g. something like:
> 
> diff --git a/www/manager6/form/VMSelector.js b/www/manager6/form/VMSelector.js
> index bf2c8df7..076360ec 100644
> --- a/www/manager6/form/VMSelector.js
> +++ b/www/manager6/form/VMSelector.js
> @@ -135,7 +135,7 @@ Ext.define('PVE.form.VMSelector', {
>         let notFound = [];
>         let selection = value.map(item => {
>             let found = store.findRecord('vmid', item, 0, false, true, true);
> -           if (!found) {
> +           if (!found && item !== '') {
>                 notFound.push(item);
>             }
>             return found;
> 
> or if we want to go above and beyond we could even do a regex match for /^[1-9][0-9]{2,}$/
> while more expensive even thousands of guests should not really add a noticeable delay,
> but just mentioning it for completeness sake.

Matching wouldn't work if the item is already a number and not a string.
Maybe do the middle way and use Ext.isNumeric?

I'll send a v2 with both changes.




      reply	other threads:[~2023-07-07  7:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-06 13:51 Fiona Ebner
2023-07-06 16:16 ` Thomas Lamprecht
2023-07-07  7:41   ` Fiona Ebner [this message]

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=906a4644-d7fa-3c71-5d51-5d45ffce9dc3@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    --cc=t.lamprecht@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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal