[pve-devel] [PATCH installer 2/5] common: fqdn: implement case-insensitive comparison as per RFC 952

Christoph Heiss c.heiss at proxmox.com
Thu Feb 15 13:39:35 CET 2024


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 at proxmox.com>
---
 proxmox-installer-common/src/utils.rs | 28 ++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/proxmox-installer-common/src/utils.rs b/proxmox-installer-common/src/utils.rs
index 067e025..0ed7438 100644
--- a/proxmox-installer-common/src/utils.rs
+++ b/proxmox-installer-common/src/utils.rs
@@ -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"));
+    }
 }
-- 
2.43.0





More information about the pve-devel mailing list