]> git.proxmox.com Git - pve-installer.git/commitdiff
common: fqdn: implement case-insensitive comparison as per RFC 952
authorChristoph Heiss <c.heiss@proxmox.com>
Thu, 15 Feb 2024 12:39:35 +0000 (13:39 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 23 Feb 2024 15:38:45 +0000 (16:38 +0100)
Multiple DNS-related RFCs (notably RFC 952, RFC 1035 and RFC 4343)
reinforce that FQDN must not be case-sensitive.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
proxmox-installer-common/src/utils.rs

index 067e0259696c0b8f3c079e22f3183de78b786664..0ed7438a0c64ab63a2c925d3bcdea9a000dc6be8 100644 (file)
@@ -154,7 +154,7 @@ impl fmt::Display for FqdnParseError {
 ///
 /// Some terminology:
 /// - "label" - a single part of a FQDN, e.g. <label>.<label>.<tld>
-#[derive(Clone, Debug, Eq, PartialEq)]
+#[derive(Clone, Debug, Eq)]
 pub struct Fqdn {
     parts: Vec<String>,
 }
@@ -257,6 +257,26 @@ impl<'de> Deserialize<'de> for Fqdn {
     }
 }
 
+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
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;
@@ -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"));
+    }
 }