CC: | 248075 [...] rt.noris.net |
Subject: | matching of hostnames with labels beginning with digits |
Currently there seems to be no way to match hostnames like 01051.com
with $RE{net}{domain}.
I'm aware that these hostnames are not valid according to RFC 1035.
They do exist, however...
01051.com. 1D IN A 213.203.202.103
01051.com. 1D IN MX 10 mail.wxx.com.
01051.com. 1D IN NS ns1.internetnamen.de.
01051.com. 1D IN NS ns2.internetnamen.de.
01051.com. 1D IN SOA ns1.internetnamen.de. [...]
... so (probably not only) I have to deal with them.
So I'd suggest adding an option to allow such labels, e.g.
{-startwithdigit} (see patch attached).
Regards,
fany
Subject: | Regexp-Common-startwithdigit.patch |
--- Regexp-Common-2.120/lib/Regexp/Common/net.pm 2004-12-29 00:31:54.000000000 +0100
+++ Regexp-Common-2.121/lib/Regexp/Common/net.pm 2006-02-16 11:46:46.000000000 +0100
@@ -69,8 +69,9 @@
my $let_dig_hyp = "[-A-Za-z0-9]";
# Domain names, from RFC 1035.
-pattern name => [qw (net domain -nospace=)],
+pattern name => [qw (net domain -nospace= -startwithdigit=)],
create => sub {
+ my $letter = defined $_[1]{-startwithdigit} ? $letter : $let_dig;
if (exists $_ [1] {-nospace} && !defined $_ [1] {-nospace}) {
return "(?k:$letter(?:(?:$let_dig_hyp){0,61}$let_dig)?" .
"(?:\\.$letter(?:(?:$let_dig_hyp){0,61}$let_dig)?)*)"
--- Regexp-Common-2.120/t/test_domain.t 2003-07-05 01:09:36.000000000 +0200
+++ Regexp-Common-2.121/t/test_domain.t 2006-02-16 11:45:34.000000000 +0100
@@ -76,3 +76,25 @@
fail 'host. .example.com';
fail 'host .example.com';
fail 'ho st.example.com';
+
+try $RE{net}{domain}{-startwithdigit};
+
+pass 'host.example.com';
+pass 'a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z';
+pass 'A.B.C.D.E.F.G.H.I.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.X.Y.Z';
+pass 'host1.example.com';
+pass 'host-1.example.com';
+pass 'host';
+pass 'a-----------------1.example.com';
+pass 'a123456a.example.com';
+pass 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789.com';
+pass ' ';
+pass '123host.example.com';
+pass 'www.01051.com';
+fail 'host-.example.com';
+fail 'host.example.com.';
+fail 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789a.com';
+fail ' ';
+fail 'host. .example.com';
+fail 'host .example.com';
+fail 'ho st.example.com';