micafer commented on code in PR #2066:
URL: https://github.com/apache/libcloud/pull/2066#discussion_r4583107703


##########
libcloud/dns/base.py:
##########
@@ -580,3 +694,19 @@ def _string_to_record_type(self, string):
         string = string.upper()
         record_type = getattr(RecordType, string)
         return record_type
+
+    @staticmethod
+    def to_default_id(zone, name, type):
+        prefix = zone.prefix(name)
+        return f"{type}:{prefix}" if prefix else str(type)
+
+    @classmethod
+    def from_default_id(cls, zone, record_id):
+        match = cls.DEFAULT_ID_RE.match(record_id)

Review Comment:
   The current implementation uses re.match() to parse record IDs. Since 
re.match() only requires a match at the beginning of the string, malformed IDs 
can be partially accepted.
   
   For example, "A:" matches the "A" prefix because the optional name group 
cannot match an empty string. As a result, the trailing colon is silently 
ignored instead of rejecting the invalid ID.
   
   Would it make sense to use re.fullmatch() instead, so the entire record ID 
must match the expected format?
   
   A regression test for malformed IDs such as "A:" would also be useful.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to