FedEx: use named captures to better resolve parts.
This is intended to fix #215. - Use named captures to make the matching more clear and resilient. - Add a test for the specific query from issue #215to demonstrate the fix.master
parent
119b23dac5
commit
15776c4f62
|
@ -24,10 +24,10 @@ my $fedex_qr = qr/fed(?:eral|)ex(?:press|)/io;
|
|||
my $tracking_qr = qr/package|track(?:ing|)|num(?:ber|)|\#/i;
|
||||
|
||||
triggers query_nowhitespace_nodash => qr/
|
||||
^$fedex_qr.*?([\d]{9,})$|
|
||||
^([\d]{9,}).*?$fedex_qr$|
|
||||
^(?:$tracking_qr|$fedex_qr|)*?(\d*?)([\d]{15,20})(?:$tracking_qr|$fedex_qr|)*$|
|
||||
^(?:$tracking_qr|$fedex_qr|)*?(\d*?)([\d]{12})(?:$tracking_qr|$fedex_qr|)*$
|
||||
^$fedex_qr.*?(?<the_number>[\d]{9,})$|
|
||||
^(?<the_number>[\d]{9,}).*?$fedex_qr$|
|
||||
^(?:$tracking_qr|$fedex_qr|)*?(?<extra_numbers>\d*?)(?<to_checksum>[\d]{15,20})(?:$tracking_qr|$fedex_qr|)*$|
|
||||
^(?:$tracking_qr|$fedex_qr|)*?(?<extra_numbers>\d*?)(?<to_checksum>[\d]{12})(?:$tracking_qr|$fedex_qr|)*$
|
||||
/xio;
|
||||
|
||||
# Fedex package tracking.
|
||||
|
@ -40,9 +40,9 @@ handle query_nowhitespace_nodash => sub {
|
|||
# Tracking number.
|
||||
my $package_number = '';
|
||||
|
||||
# Exclsuive trigger.
|
||||
if ($1 || $2) {
|
||||
$package_number = $1 || $2;
|
||||
# Exclusive trigger.
|
||||
if ($+{the_number}) {
|
||||
$package_number = $+{the_number};
|
||||
$is_fedex = 2;
|
||||
|
||||
# No exclusive trigger, do checksum.
|
||||
|
@ -50,9 +50,9 @@ handle query_nowhitespace_nodash => sub {
|
|||
# we are more strict in regex (e.g. than UPS).
|
||||
# 15 has to be before 12 or it will block.
|
||||
}
|
||||
elsif (($3 && $4) || ($5 && $6)) {
|
||||
my $package_beg = $3 || $5;
|
||||
$package_number = $4 || $6;
|
||||
elsif ($+{to_checksum}) {
|
||||
my $package_beg = $+{some_numbers};
|
||||
$package_number = $+{to_checksum};
|
||||
|
||||
my $checksum = -1;
|
||||
my @chars = split( //, $package_number );
|
||||
|
@ -116,4 +116,4 @@ handle query_nowhitespace_nodash => sub {
|
|||
return;
|
||||
};
|
||||
|
||||
1;
|
||||
1;
|
||||
|
|
|
@ -20,6 +20,11 @@ ddg_goodie_test(
|
|||
heading => 'FedEx Shipment Tracking',
|
||||
html => qq(Track this shipment at <a href="http://fedex.com/Tracking?tracknumbers=9241990100130206401644&action=track">FedEx</a>.)
|
||||
),
|
||||
'178440515632684' => test_zci(
|
||||
"178440515632684",
|
||||
heading => 'FedEx Shipment Tracking',
|
||||
html => qq(Track this shipment at <a href="http://fedex.com/Tracking?tracknumbers=178440515632684&action=track">FedEx</a>.)
|
||||
),
|
||||
);
|
||||
|
||||
done_testing;
|
||||
|
|
Loading…
Reference in New Issue