Skip to content

Commit 7398148

Browse files
committed
- Added support for Unicode characters in station names.
- Added support for Unicode characters in line names. - Added unit test for Unicode characters in station and line names.
1 parent 65823f5 commit 7398148

File tree

15 files changed

+95
-34
lines changed

15 files changed

+95
-34
lines changed

Changes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Revision history for Map::Tube
22

3+
4.08 2025-04-22T20:10:00+00:00
4+
- Added support for Unicode characters in station names.
5+
- Added support for Unicode characters in line names.
6+
- Added unit test for Unicode characters in station and line names.
7+
38
4.07 2025-04-17T15:50:00+00:00
49
- Renamed Forked test to OtherLink test to be more explicit.
510

MANIFEST

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ t/Sample.pm
4040
t/OtherLink.pm
4141
t/other-link-map.xml
4242
t/sample.xml
43+
t/unicode-map.xml
44+
t/unicode-map.t
4345
t/lib/BadSample.pm
4446
t/lib/Sample.pm
4547
t/lib/SampleJson.pm

Makefile.PL

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ WriteMakefile(
5252
(eval { ExtUtils::MakeMaker->VERSION(6.46) } ? (META_MERGE => {
5353
'meta-spec' => { version => 2 },
5454
provides => {
55-
'Map::Tube' => { file => 'lib/Map/Tube.pm' , version => '4.07' },
56-
'Map::Tube::Node' => { file => 'lib/Map/Tube/Node.pm' , version => '4.07' },
57-
'Map::Tube::Line' => { file => 'lib/Map/Tube/Line.pm' , version => '4.07' },
58-
'Map::Tube::Table' => { file => 'lib/Map/Tube/Table.pm' , version => '4.07' },
59-
'Map::Tube::Route' => { file => 'lib/Map/Tube/Route.pm' , version => '4.07' },
60-
'Map::Tube::Utils' => { file => 'lib/Map/Tube/Utils.pm' , version => '4.07' },
61-
'Map::Tube::Types' => { file => 'lib/Map/Tube/Types.pm' , version => '4.07' },
62-
'Map::Tube::Cookbook' => { file => 'lib/Map/Tube/Cookbook.pm' , version => '4.07' },
63-
'Map::Tube::Pluggable' => { file => 'lib/Map/Tube/Pluggable.pm', version => '4.07' },
64-
'Test::Map::Tube' => { file => 'lib/Test/Map/Tube.pm' , version => '4.07' },
55+
'Map::Tube' => { file => 'lib/Map/Tube.pm' , version => '4.08' },
56+
'Map::Tube::Node' => { file => 'lib/Map/Tube/Node.pm' , version => '4.08' },
57+
'Map::Tube::Line' => { file => 'lib/Map/Tube/Line.pm' , version => '4.08' },
58+
'Map::Tube::Table' => { file => 'lib/Map/Tube/Table.pm' , version => '4.08' },
59+
'Map::Tube::Route' => { file => 'lib/Map/Tube/Route.pm' , version => '4.08' },
60+
'Map::Tube::Utils' => { file => 'lib/Map/Tube/Utils.pm' , version => '4.08' },
61+
'Map::Tube::Types' => { file => 'lib/Map/Tube/Types.pm' , version => '4.08' },
62+
'Map::Tube::Cookbook' => { file => 'lib/Map/Tube/Cookbook.pm' , version => '4.08' },
63+
'Map::Tube::Pluggable' => { file => 'lib/Map/Tube/Pluggable.pm', version => '4.08' },
64+
'Test::Map::Tube' => { file => 'lib/Test/Map/Tube.pm' , version => '4.08' },
6565
},
6666
prereqs => {
6767
test => {

lib/Map/Tube.pm

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package Map::Tube;
22

3-
$Map::Tube::VERSION = '4.07';
3+
$Map::Tube::VERSION = '4.08';
44
$Map::Tube::AUTHORITY = 'cpan:MANWAR';
55

66
=head1 NAME
@@ -9,7 +9,7 @@ Map::Tube - Lightweight Routing Framework.
99
1010
=head1 VERSION
1111
12-
Version 4.07
12+
Version 4.08
1313
1414
=cut
1515

@@ -418,6 +418,7 @@ sub get_line_by_name {
418418
line_number => $caller[2] }) unless defined $name;
419419

420420
my $line = $self->_get_line_object_by_name($name);
421+
$name = _decode_utf8_if_needed($name);
421422
Map::Tube::Exception::InvalidLineName->throw({
422423
method => __PACKAGE__."::get_line_by_name",
423424
message => "ERROR: Invalid Line Name [$name].",
@@ -935,7 +936,7 @@ sub _init_map {
935936
}
936937
my $master_line_data = {};
937938
foreach (@lines) {
938-
$master_line_data->{lc $_->{id}} = 1;
939+
$master_line_data->{NFC(lc $_->{id})} = 1;
939940
}
940941

941942
my $has_station_index = {};
@@ -967,7 +968,8 @@ sub _init_map {
967968
$has_station_index->{$_line} = 1;
968969
}
969970

970-
if (!exists $master_line_data->{lc $_line}) {
971+
$_line = _decode_utf8_if_needed($_line);
972+
if (!exists $master_line_data->{NFC(lc $_line)}) {
971973
Map::Tube::Exception::InvalidStationLineId->throw({
972974
method => $method,
973975
message => "ERROR: Invalid line [$_line] for station [$name].",
@@ -1046,6 +1048,16 @@ sub _init_map {
10461048
$self->tables($tables);
10471049
}
10481050

1051+
sub _decode_utf8_if_needed {
1052+
my ($data) = @_;
1053+
1054+
if (!utf8::is_utf8($data) && utf8::valid($data)) {
1055+
$data = decode_utf8($data);
1056+
}
1057+
1058+
return $data;
1059+
}
1060+
10491061
sub _is_directly_linked {
10501062
my ($self, $start_station, $end_station) = @_;
10511063
my $linked_stations = $self->get_linked_stations($start_station);
@@ -1269,15 +1281,16 @@ sub _get_node_id {
12691281
return unless defined $name;
12701282
$name =~ s/^\s+//;
12711283
$name =~ s/\s+$//;
1272-
$name = decode_utf8($name) if !utf8::is_utf8($name) && utf8::valid($name);
1284+
$name = _decode_utf8_if_needed($name);
12731285
$name = NFC(uc($name));
12741286
return $self->{name_to_id}->{$name};
12751287
}
12761288

12771289
sub _get_line_object_by_name {
12781290
my ($self, $name) = @_;
12791291

1280-
$name = uc($name);
1292+
$name = _decode_utf8_if_needed($name);
1293+
$name = NFC(uc($name));
12811294
foreach my $line_id (keys %{$self->{_lines}}) {
12821295
my $line = $self->{_lines}->{$line_id};
12831296
if (defined $line && defined $line->name) {

lib/Map/Tube/Cookbook.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package Map::Tube::Cookbook;
22

3-
$Map::Tube::Cookbook::VERSION = '4.07';
3+
$Map::Tube::Cookbook::VERSION = '4.08';
44
$Map::Tube::Cookbook::AUTHORITY = 'cpan:MANWAR';
55

66
=head1 NAME
@@ -9,7 +9,7 @@ Map::Tube::Cookbook - Cookbook for Map::Tube library.
99
1010
=head1 VERSION
1111
12-
Version 4.07
12+
Version 4.08
1313
1414
=cut
1515

lib/Map/Tube/Line.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package Map::Tube::Line;
22

3-
$Map::Tube::Line::VERSION = '4.07';
3+
$Map::Tube::Line::VERSION = '4.08';
44
$Map::Tube::Line::AUTHORITY = 'cpan:MANWAR';
55

66
=head1 NAME
@@ -9,7 +9,7 @@ Map::Tube::Line - Class to represent the line in the map.
99
1010
=head1 VERSION
1111
12-
Version 4.07
12+
Version 4.08
1313
1414
=cut
1515

lib/Map/Tube/Node.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package Map::Tube::Node;
22

3-
$Map::Tube::Node::VERSION = '4.07';
3+
$Map::Tube::Node::VERSION = '4.08';
44
$Map::Tube::Node::AUTHORITY = 'cpan:MANWAR';
55

66
=head1 NAME
@@ -9,7 +9,7 @@ Map::Tube::Node - Class to represent the station in the map.
99
1010
=head1 VERSION
1111
12-
Version 4.07
12+
Version 4.08
1313
1414
=cut
1515

lib/Map/Tube/Pluggable.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package Map::Tube::Pluggable;
22

3-
$Map::Tube::Pluggable::VERSION = '4.07';
3+
$Map::Tube::Pluggable::VERSION = '4.08';
44
$Map::Tube::Pluggable::AUTHORITY = 'cpan:MANWAR';
55

66
=head1 NAME
@@ -9,7 +9,7 @@ Map::Tube::Pluggable - Class to load plugins for Map::Tube.
99
1010
=head1 VERSION
1111
12-
Version 4.07
12+
Version 4.08
1313
1414
=cut
1515

lib/Map/Tube/Route.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package Map::Tube::Route;
22

3-
$Map::Tube::Route::VERSION = '4.07';
3+
$Map::Tube::Route::VERSION = '4.08';
44
$Map::Tube::Route::AUTHORITY = 'cpan:MANWAR';
55

66
=head1 NAME
@@ -9,7 +9,7 @@ Map::Tube::Route - Class to represent the route in the map.
99
1010
=head1 VERSION
1111
12-
Version 4.07
12+
Version 4.08
1313
1414
=cut
1515

lib/Map/Tube/Table.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package Map::Tube::Table;
22

3-
$Map::Tube::Table::VERSION = '4.07';
3+
$Map::Tube::Table::VERSION = '4.08';
44
$Map::Tube::Table::AUTHORITY = 'cpan:MANWAR';
55

66
=head1 NAME
@@ -9,7 +9,7 @@ Map::Tube::Table - Class to represent the table in the map.
99
1010
=head1 VERSION
1111
12-
Version 4.07
12+
Version 4.08
1313
1414
=cut
1515

0 commit comments

Comments
 (0)