Skip to content

Commit 02fd370

Browse files
committed
#31 - Fix case when first encountered byte of metadata separator is false positive.
1 parent 2f71bf6 commit 02fd370

4 files changed

Lines changed: 7 additions & 4 deletions

File tree

META6.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name" : "GeoIP2",
3-
"version" : "1.1.3",
3+
"version" : "1.1.4",
44
"description" : "MaxMind GeoIP v2 databases reader.",
55
"authors" : [ "Paweł bbkr Pabian" ],
66
"auth": "zef:bbkr",

lib/GeoIP2.rakumod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ method !read-metadata ( ) returns Hash {
144144
next unless $byte == 0xAB;
145145

146146
# marker found, cursor will be positioned right after it
147-
last if $!handle.read( $metadata-marker.elems ) == $metadata-marker;
147+
last if $!handle.read( $metadata-marker.elems ) ~~ $metadata-marker;
148148

149149
# marker not found, rewind cursor to previous position
150150
$!handle.seek( -$metadata-marker.elems, SeekFromCurrent );
151151
}
152-
152+
153153
# decode metadata section into map structure
154154
return self!read-data( );
155155
}

t/00-reader.rakutest

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ lives-ok { $geo = GeoIP2.new( path => './t/databases/MaxMind-DB-test-decoder.mmd
2222

2323
subtest 'metadata' => sub {
2424

25-
plan 13;
25+
plan 14;
2626

2727
is $geo.binary-format-version, v2.0, 'binary format version';
2828
is $geo.build-timestamp.Str, '2015-07-15T17:38:55Z', 'build timestamp';
@@ -40,6 +40,8 @@ subtest 'metadata' => sub {
4040
is $geo.record-size, 24, 'record size';
4141
is $geo.search-tree-size, 2370, 'search tree size';
4242

43+
lives-ok { GeoIP2.new( path => './t/databases/metadata-backtrack.mmdb' ) }, 'first encountered byte of separator is false positive';
44+
4345
}
4446

4547
subtest 'data types' => sub {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
���MaxMind.com�[binary_format_major_version�[binary_format_minor_version�Kbuild_epochgj�Mdatabase_typeMGeoLite2-CityKdescription�BenUGeoLite2City databaseJip_version�IlanguagesBdeBenBesBfrBjaEpt-BRBruEzh-CNJnode_count�N�`Krecord_size�

0 commit comments

Comments
 (0)