Creation Date isn't being parsed
papaiatis opened this issue · comments
Hi,
I'm trying to get whois information for domains and in same cases the Creation Date field isn't being parsed. For example with this domain: loloscube dot com
The Creation Date is in the Verisign's response but the resulting json does not contain a separate creation_date field.
Since I'm new to Ruby I'm having a hard time debugging the code :)
Can you please help me out?
Thanks!
I think I found the problem. In Whois::Record::Parser
the delegate_property_to_parsers
calls the select_parser
method to get a parser which supports the created_on
property. The parsers
array contains these parsers in this order:
Whois::Record::Parsers::WhoisGodaddyCom
Whois::Record::Parsers::WhoisGodaddyCom
Whois::Record::Parsers::WhoisVerisignGrsCom
Since both types of parsers support the created_on
property the first GodaddyCom parser will be selected. However the @part
string belonging to the selected first GodaddyCom parser does not contain the Creation Date
string but only the VerisignGrsCom parser's @part
string.
Because the delegate_property_to_parsers
method does not check if the parser supports the property AND
returns the property's value properly (not nil) it does not reach out to the VerisignGrsCom parser (which only contains this information).
I temporarily changed the created_on
to property_not_supported
in GodaddyCom
parser. This make the code select the VerisignGrsCom
parser which eventually successfully returned the Creation Date string.
There should be a logic in delegate_property_to_parsers
which iterates through all the parsers that supports the selected property and it only stops if the current parser successfully returns a valid value or there is no more parsers left (thus returns nil eventually).
Any thoughts?
I managed to fix the bug.
Here is the old code:
def delegate_property_to_parsers(method, *args, &block)
if parsers.empty?
raise ParserError, "Unable to select a parser because the Record is empty"
elsif (parser = select_parser { |p| p.class.property_state?(method, PROPERTY_STATE_SUPPORTED) })
parser.send(method, *args, &block)
elsif (parser = select_parser { |p| p.class.property_state?(method, PROPERTY_STATE_NOT_SUPPORTED) })
parser.send(method, *args, &block)
else
raise AttributeNotImplemented, "Unable to find a parser for property `#{method}'"
end
end
And here is the fixed one:
def delegate_property_to_parsers(method, *args, &block)
if parsers.empty?
raise ParserError, "Unable to select a parser because the Record is empty"
end
states = [ PROPERTY_STATE_SUPPORTED, PROPERTY_STATE_NOT_SUPPORTED ]
property_value = nil
parser_found = false
states.each do |state|
parsers.each do |parser|
if parser.class.property_state?(method, state)
parser_found = true
property_value = parser.send(method, *args, &block)
if not property_value.nil?
return property_value
end
end
end
end
if not parser_found
raise AttributeNotImplemented, "Unable to find a parser for property `#{method}'"
end
end
However, I did not find this file in the upcoming new version of the whois gem (4.0).
Whois parsers are now defined in a separate gem.
https://github.com/weppos/whois-parser
Do you mind to report the issue in the new repository?