From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 72E3DC51B for ; Fri, 7 Jul 2023 09:42:28 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 52D2126CCE for ; Fri, 7 Jul 2023 09:41:58 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 7 Jul 2023 09:41:57 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 46ED646F7D for ; Fri, 7 Jul 2023 09:41:57 +0200 (CEST) Message-ID: <906a4644-d7fa-3c71-5d51-5d45ffce9dc3@proxmox.com> Date: Fri, 7 Jul 2023 09:41:52 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 To: Thomas Lamprecht , Proxmox VE development discussion References: <20230706135125.60221-1-f.ebner@proxmox.com> <5c9ba76f-e505-822f-237d-b2dcdce347d2@proxmox.com> Content-Language: en-US From: Fiona Ebner In-Reply-To: <5c9ba76f-e505-822f-237d-b2dcdce347d2@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.000 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.091 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox.com] Subject: Re: [pve-devel] [PATCH stable-7+master manager] ui: vm selector: handle empty string gracefully X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Jul 2023 07:42:28 -0000 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 >> --- >> 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.