diff options
author | Daniel Friesel <derf@finalrewind.org> | 2020-11-22 19:44:25 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2020-11-22 19:44:25 +0100 |
commit | 18e7135cca2d7ff6fccc2b14f8c1bbf7cf4554ff (patch) | |
tree | 7996548f8f4f4a967fedc3b80e5ed23e25da1e8b /lib/Travel/Status/DE/IRIS | |
parent | c3ca160d01cf1b10f8ae20fb2425826d28297122 (diff) |
Stations::get_station_by_name: catch invalid regular expressions
Diffstat (limited to 'lib/Travel/Status/DE/IRIS')
-rw-r--r-- | lib/Travel/Status/DE/IRIS/Stations.pm.PL | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/Travel/Status/DE/IRIS/Stations.pm.PL b/lib/Travel/Status/DE/IRIS/Stations.pm.PL index b19043f..3547448 100644 --- a/lib/Travel/Status/DE/IRIS/Stations.pm.PL +++ b/lib/Travel/Status/DE/IRIS/Stations.pm.PL @@ -41,24 +41,18 @@ our $VERSION = '1.51'; my @stations = ( EOF -for my $station (@{$stations}) { - if ($station->{latlong}) { +for my $station ( @{$stations} ) { + if ( $station->{latlong} ) { $buf .= sprintf( "['%s','%s',%s,%s,%s],\n", - $station->{ds100}, - $station->{name}, - $station->{eva}, - $station->{latlong}[1], + $station->{ds100}, $station->{name}, + $station->{eva}, $station->{latlong}[1], $station->{latlong}[0], ); } else { - $buf .= sprintf( - "['%s','%s',%s],\n", - $station->{ds100}, - $station->{name}, - $station->{eva} - ); + $buf .= sprintf( "['%s','%s',%s],\n", + $station->{ds100}, $station->{name}, $station->{eva} ); } } @@ -148,7 +142,12 @@ sub get_station_by_name { my $min_dist = min(@distances); my @station_map = pairwise { [ $a, $b ] } @stations, @distances; - my @substring_matches = grep { $_->[1] =~ m{$name}i } @stations; + my @substring_matches; + + # $name may be an invalid regular expression + eval { push(@substring_matches, grep { $_->[1] =~ m{\Q$name\E}i } @stations) }; + eval { push(@substring_matches, grep { $_->[1] =~ m{$name}i } @stations) }; + my @levenshtein_matches = map { $_->[0] } grep { $_->[1] == $min_dist } @station_map; @@ -297,4 +296,4 @@ station data used by this module is also available under a CC-BY 4.0 license on L<http://data.deutschebahn.com/dataset/data-haltestellen>. EOF -write_file($ARGV[0], {binmode => ':utf8'}, $buf); +write_file( $ARGV[0], { binmode => ':utf8' }, $buf ); |