@@ -58,6 +58,18 @@ class DNSLabel(object):
58
58
True
59
59
>>> l3.matchGlob("*.[abc]xx.bbb.ccc")
60
60
False
61
+ >>> l1.matchWildcard("*.bbb.ccc")
62
+ True
63
+ >>> l1.matchWildcard("*.CCC")
64
+ True
65
+ >>> l1.matchWildcard("*.xxx.bbb.ccc")
66
+ False
67
+ >>> l1.matchWildcard("aaa.bbb.ccc")
68
+ True
69
+ >>> l1.matchWildcard("bbb.ccc")
70
+ False
71
+ >>> l1.matchWildcard("xxx.aaa.bbb.ccc")
72
+ False
61
73
62
74
# Too hard to get unicode doctests to work on Python 3.2
63
75
# (works on 3.3)
@@ -110,6 +122,26 @@ def matchGlob(self,pattern):
110
122
pattern = DNSLabel (pattern )
111
123
return fnmatch .fnmatch (str (self ).lower (),str (pattern ).lower ())
112
124
125
+ def matchWildcard (self ,pattern ):
126
+ """
127
+ Wildcard match according to https://datatracker.ietf.org/doc/html/rfc1034#section-4.3.3
128
+ (This only allows a single '*' prefix wildcard which matches one or more labels)
129
+
130
+ Note that the spec is defined at the zone level (if there is a more
131
+ specific overlapping match within the zone) some soem additional
132
+ logic is required in the resolved to implement this.
133
+
134
+ """
135
+ if type (pattern ) != DNSLabel :
136
+ pattern = DNSLabel (pattern )
137
+ if pattern .label [0 ] != b'*' and len (self .label ) != len (pattern .label ):
138
+ # No wildcard - number of labels must match
139
+ return False
140
+ for (a ,b ) in zip (reversed (self .label ),reversed (pattern .label )):
141
+ if b != b'*' and a .lower () != b .lower ():
142
+ return False
143
+ return True
144
+
113
145
def matchSuffix (self ,suffix ):
114
146
"""
115
147
Return True if label suffix matches
0 commit comments