summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDerf Null <derf@finalrewind.org>2023-06-07 23:04:00 +0200
committerDerf Null <derf@finalrewind.org>2023-06-07 23:04:00 +0200
commite275fc6dbe84afa1c6dcff51ea34f35415a4f771 (patch)
treeb14371af291ecc47db1f53c1842a231e757939d4 /lib
parentcc4feebe2c457265f62a466ab7b5742010cc753b (diff)
Fix edge case that allowed in-transit journeys with invalid destinations1.32.2
Diffstat (limited to 'lib')
-rwxr-xr-xlib/Travelynx.pm20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index 6dd77fd..9dc1aff 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -519,6 +519,26 @@ sub startup {
delete $journey->{edited};
delete $journey->{id};
+ # users may force checkouts at stations that are not part of
+ # the train's scheduled (or real-time) route. re-adding those
+ # to in-transit violates the assumption that each train has
+ # a valid destination. Remove the target in this case.
+ my $route = JSON->new->decode( $journey->{route} );
+ my $found_checkout_id;
+ for my $stop ( @{$route} ) {
+ if ( $stop->[1] == $journey->{checkout_station_id} ) {
+ $found_checkout_id = 1;
+ last;
+ }
+ }
+ if ( not $found_checkout_id ) {
+ $journey->{checkout_station_id} = undef;
+ $journey->{checkout_time} = undef;
+ $journey->{arr_platform} = undef;
+ $journey->{sched_arrival} = undef;
+ $journey->{real_arrival} = undef;
+ }
+
$self->in_transit->add_from_journey(
db => $db,
journey => $journey