all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Christoph Heiss <c.heiss@proxmox.com>
Subject: Re: [pve-devel] [PATCH installer 2/5] common: fqdn: implement case-insensitive comparison as per RFC 952
Date: Fri, 23 Feb 2024 17:10:37 +0100	[thread overview]
Message-ID: <a8827806-ba52-43f1-b5d0-ee4fc8c20627@proxmox.com> (raw)
In-Reply-To: <20240215124004.1197676-3-c.heiss@proxmox.com>

Am 15/02/2024 um 13:39 schrieb Christoph Heiss:
> +impl PartialEq for Fqdn {
> +    fn eq(&self, other: &Self) -> bool {
> +        // Case-insensitive comparison, as per RFC 952 "ASSUMPTIONS",
> +        // RFC 1035 sec. 2.3.3. "Character Case" and RFC 4343 as a whole
> +        let a = self
> +            .parts
> +            .iter()
> +            .map(|s| s.to_lowercase())
> +            .collect::<Vec<String>>();
> +
> +        let b = other
> +            .parts
> +            .iter()
> +            .map(|s| s.to_lowercase())
> +            .collect::<Vec<String>>();
> +
> +        a == b

could be probably more efficiently done by doing the comparison part wise, not
on the whole thing, and with an early abort for mismatching part count, e.g.,
something like:

if self.parts.len() != other.parts.len() {             
    return false;                                      
}                                                      
                                                       
self.parts                                             
    .iter()                                            
    .zip(other.parts.iter())                           
    .all(|(a, b)| a.to_lowercase() == b.to_lowercase())

> @@ -309,4 +329,10 @@ mod tests {
>              "foo.example.com"
>          );
>      }
> +
> +    #[test]
> +    fn fqdn_compare() {
> +        assert_eq!(Fqdn::from("example.com"), Fqdn::from("ExAmPle.Com"));
> +        assert_eq!(Fqdn::from("ExAmPle.Com"), Fqdn::from("example.com"));

I always like throwing in some assert_ne ones for sanity checking (e.g., such
optimization tries like above), as otherwise one won't notice if this is broken,
like by just always returning false..





  reply	other threads:[~2024-02-23 16:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-15 12:39 [pve-devel] [PATCH installer 0/5] proxinstall, tui: improve hostname/FQDN validation Christoph Heiss
2024-02-15 12:39 ` [pve-devel] [PATCH installer 1/5] common: fqdn: do not allow overlong FQDNs as per Debian spec Christoph Heiss
2024-02-15 12:39 ` [pve-devel] [PATCH installer 2/5] common: fqdn: implement case-insensitive comparison as per RFC 952 Christoph Heiss
2024-02-23 16:10   ` Thomas Lamprecht [this message]
2024-02-15 12:39 ` [pve-devel] [PATCH installer 3/5] proxinstall: avoid open-coding FQDN sanity check Christoph Heiss
2024-02-15 12:39 ` [pve-devel] [PATCH installer 4/5] sys: net: do not allow overlong FQDNs as per RFCs and Debian spec Christoph Heiss
2024-02-15 12:39 ` [pve-devel] [PATCH installer 5/5] fix #5230: sys: net: properly escape FQDN regex Christoph Heiss
2024-02-23 16:27   ` Thomas Lamprecht
2024-02-26  9:04     ` Christoph Heiss
2024-02-23 16:31 ` [pve-devel] applied-series: [PATCH installer 0/5] proxinstall, tui: improve hostname/FQDN validation Thomas Lamprecht

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=a8827806-ba52-43f1-b5d0-ee4fc8c20627@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=c.heiss@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 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