]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
If present, top-level domain must be alphabetic
authorRod Montgomery <rmontgomery@dealnews.com>
Thu, 15 Jan 2015 21:10:33 +0000 (15:10 -0600)
committerRod Montgomery <rmontgomery@dealnews.com>
Fri, 6 Mar 2015 03:51:12 +0000 (21:51 -0600)
See RFC 1123, Section 2.1
http://tools.ietf.org/html/rfc1123#section-2

lib/puppet/parser/functions/is_domain_name.rb
spec/functions/is_domain_name_spec.rb

index 2860dede59fdf84ea056bad9de847a90dc423ea1..90ede32722852165ff28eb2ee1f5116adc09d504 100644 (file)
@@ -33,6 +33,10 @@ Returns true if the string passed to this function is a syntactically correct do
     return false if domain.empty?
     return false if domain.length > domain_max_length
 
+    # The top level domain must be alphabetic if there are multiple labels.
+    # See rfc1123, 2.1
+    return false if domain.include? '.' and not /\.[A-Za-z]+$/.match(domain)
+
     # Check each label in the domain
     labels = domain.split('.')
     vlabels = labels.each do |label|
index 5ab8369c07d3ce20a283233eb5a94709496ca74d..ef880612fe5c899b0fd4cbdc1bae8fedc2347093 100755 (executable)
@@ -68,4 +68,14 @@ describe "the is_domain_name function" do
     result = scope.function_is_domain_name(["my.domain.name".freeze])
     expect(result).to(be_truthy)
   end
+
+  it "should return false if top-level domain is not entirely alphabetic" do
+    result = scope.function_is_domain_name(["kiwi.2bar"])
+    expect(result).to(be_falsey)
+  end
+
+  it "should return false if domain name has the dotted-decimal form, e.g. an IPv4 address" do
+    result = scope.function_is_domain_name(["192.168.1.1"])
+    expect(result).to(be_falsey)
+  end
 end