Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/Geo/Address/Formatter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ sub format_address {

# 2. deal with the options

foreach (grep { ! /^[a-z0-9_]+$/ } keys %$rh_components) {
if ($debug){
say STDERR "Skipping compontent $_";
}
delete $rh_components->{$_};
}

# 2a. which country format will we use?
# might have been specified in options
# otherwise look at components
Expand Down
26 changes: 26 additions & 0 deletions t/unit/formatter.t
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ my $GAF = $CLASS->new(conf_path => $path);
}
}

# Make sure invalid component names are skipped
{
my $af_path = dirname(__FILE__) . '/../../address-formatting';
my $conf_path = $af_path . '/conf/';
my $GAF = $CLASS->new(conf_path => $conf_path);

my $rh_components = {
'' => 'empty',
'*' => 'star',
'+' => 'plus',
'\\' => 'escape',
'$' => 'dollar',
'(' => 'bracket',
'\(' => 'quoted bracket',
'country' => 'United Kingdom',
'country_code' => 'gb',
};

my $formatted = $GAF->format_address($rh_components, {});
chomp $formatted;

is($formatted, 'United Kingdom');
}



{
# keep in mind this is using the test conf, not the real address-formatting conf
is($GAF->_add_state_code({}), undef);
Expand Down
Loading