Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Conversation

@TBSliver
Copy link
Contributor

No description provided.

Copy link
Contributor

@xdg xdg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this passes test so that's awesome! My comments are mostly style and clarity with a just few edge cases that need fixing.

(
$result{username}, $result{password}, $result{hostids},
$result{db_name}, $result{options}
) = ( $1, $2, $3, $4, $5 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match line 346, I think you should run _unescape_all on hostids if defined. That would make me more confident about the check at line 231 and so on.

$result{options} = $self->_parse_options( $valid, \%result );
}

require Net::DNS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please pull the DNS parts out to a separate subroutine? Maybe returning \@hosts and $options? I think it would make this subroutine easier to read and follow.


my @hosts;
my $options = {};
my @split_name = split( '\.', $result{hostids} );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if you get at least 2 parts before indexing [1..$#split_name] next.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this might need to be three? The spec talks about {hostname}.{domainname} where {domainname} is supposed to be at least two parts.

next unless $rr->type eq 'SRV';
my $target = $rr->target;
# search for dot before domain name for a valid hostname - can have sub-subdomain
unless ( $target =~ /\.${\$domain_name}$/ ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with this idiom for regex interpolation. Why not $target =~ /\.\Q$domain_name\E$/?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah this was just cos I was thinking in string interpolation mode and it worked. Will swap it over as its not a documented way of doing it as far as i can see in perlre

my $domain_name = join( '.', @split_name[1..$#split_name] );
if ( $srv_data ) {
foreach my $rr ( $srv_data->answer ) {
next unless $rr->type eq 'SRV';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed if we queried for 'SRV'?

}
}
$result{options} = \%parsed;
$result{options} = $self->_parse_options( $valid, \%result );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get rid of the temporary $valid here.

return $set;
}

use Devel::Dwarn;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...oops


use Devel::Dwarn;
sub _parse_options {
my ( $self, $valid, $result, $err_unsupported ) = @_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than a boolean $err_unsupported I think we should pass in the TXT record itself for use in errors, so s/err_unsupported/txt_record/

( my $lc_k = $k ) =~ tr[A-Z][a-z];
if ( !$valid->{$lc_k} ) {
if ( $err_unsupported ) {
MongoDB::Error->throw("Unsupported option '$k' in URI $self\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I think we'll be less confusing if we reported the TXT records. "... in URI $self with TXT record $txt_record ..."

next;
}
if ( exists $parsed{$lc_k} && !exists $options_with_list_type{$lc_k} ) {
warn "Multiple options were found for the same value '$lc_k'\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as I'm looking at this, we should have the warning message clarify that only the first one is used.

@TBSliver
Copy link
Contributor Author

Changes pushed. Have left the checks for SRV and TXT records in as I am unsure without diving through most of the DNS specs to figure out if it will actually return anything BUT those in a request - however Net::DNS::RR does warn against not checking first: https://metacpan.org/pod/Net::DNS::RR#METHODS so am erring on the side of caution!

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.3%) to 82.527% when pulling cbaf778 on shadow-dot-cat:TBSliver/PERL-807 into e477f53 on mongodb:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.3%) to 82.507% when pulling 0a3989c on shadow-dot-cat:TBSliver/PERL-807 into e477f53 on mongodb:master.

@xdg
Copy link
Contributor

xdg commented Jan 17, 2018

Squashed and committed as 32e90bc

@xdg xdg closed this Jan 17, 2018
@TBSliver TBSliver deleted the TBSliver/PERL-807 branch January 25, 2018 11:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants