Skip to content

Commit

Permalink
fix invalid $ORIGIN record
Browse files Browse the repository at this point in the history
  • Loading branch information
dmke committed Jul 12, 2019
1 parent bc3c010 commit e9be00d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/zonefile/zonefile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,18 @@ def self.from_file(file_name, origin = nil)
def initialize(zonefile = "", file_name = nil, origin = nil)
@data = zonefile
@filename = file_name
@origin = origin || (file_name ? file_name.split("/").last : "")
self.origin = origin || (file_name ? file_name.split("/").last : "")

@records = {}
@soa = {}
RECORDS.each {|r| @records[r] = [] }
parse
end

def origin=(val)
@origin = val.chomp(".")
end

# True if no records (except sao) is defined in this file
def empty?
RECORDS.each do |r|
Expand Down Expand Up @@ -224,7 +228,7 @@ def parse

def parse_line(line)
if (origin = Parser::DIRECTIVE_ORIGIN.match(line))
@origin = origin
self.origin = origin
elsif (ttl = Parser::DIRECTIVE_TTL.match(line))
@ttl = ttl
elsif (data = Parser::SOA.match(line))
Expand Down Expand Up @@ -640,6 +644,9 @@ def output
; Database file #{@filename || 'unknown'} for #{@origin || 'unknown'} zone.
; Zone version: #{soa[:serial]}
;
#{@origin ? "$ORIGIN #{@origin}." : ''}
#{@ttl ? "$TTL #{@ttl}" : ''}
#{soa[:origin]}\t#{soa[:ttl]}\tIN\tSOA\t(
\t\t\t\t\t#{soa[:primary]}\t; primary
\t\t\t\t\t#{soa[:email]}\t; email
Expand All @@ -649,9 +656,6 @@ def output
\t\t\t\t\t#{soa[:expire]}\t; expire
\t\t\t\t\t#{soa[:minimumTTL]}\t; minimum TTL
\t\t\t\t)
#{@origin ? "$ORIGIN #{@origin}" : ''}
#{@ttl ? "$TTL #{@ttl}" : ''}
ENDH

{
Expand Down

0 comments on commit e9be00d

Please sign in to comment.