Skip to content

Commit 75de610

Browse files
committed
DB: fix parsing of ticket URLs 🐛
URL.prototype.searchParams is read-only, so we just mutate it. follow-up of c4966ae
1 parent e9211e8 commit 75de610

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

p/db/index.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -261,32 +261,29 @@ const addDbOfferSelectionUrl = (journey, opt) => {
261261

262262
// if no ticket contains addData, we can't get the offer selection URL
263263
if (journey.tickets.some((t) => t.addDataTicketInfo)) {
264-
265-
const queryParams = new URLSearchParams();
266-
267-
// Add individual parameters
268-
queryParams.append('A.1', opt.age);
269-
queryParams.append('E', 'F');
270-
queryParams.append('E.1', opt.loyaltyCard ? formatLoyaltyCard(opt.loyaltyCard) : '0');
271-
queryParams.append('K', opt.firstClass ? '1' : '2');
272-
queryParams.append('M', 'D');
273-
queryParams.append('RT.1', 'E');
274-
queryParams.append('SS', journey.legs[0].origin.id);
275-
queryParams.append('T', journey.legs[0].departure);
276-
queryParams.append('VH', journey.refreshToken);
277-
queryParams.append('ZS', journey.legs[journey.legs.length - 1].destination.id);
278-
queryParams.append('journeyOptions', '0');
279-
queryParams.append('journeyProducts', '1023');
280-
queryParams.append('optimize', '1');
281-
queryParams.append('returnurl', 'dbnavigator://');
282264
const endpoint = opt.language === 'de' ? 'dox' : 'eox';
283265

284266
journey.tickets.forEach((t) => {
285267
const shpCtx = parseShpCtx(t.addDataTicketInfo);
286268
if (shpCtx) {
287269
const url = new URL(`https://mobile.bahn.de/bin/mobil/query.exe/${endpoint}`);
288-
url.searchParams = new URLSearchParams(queryParams);
270+
271+
url.searchParams.append('A.1', opt.age);
272+
url.searchParams.append('E', 'F');
273+
url.searchParams.append('E.1', opt.loyaltyCard ? formatLoyaltyCard(opt.loyaltyCard) : '0');
274+
url.searchParams.append('K', opt.firstClass ? '1' : '2');
275+
url.searchParams.append('M', 'D');
276+
url.searchParams.append('RT.1', 'E');
277+
url.searchParams.append('SS', journey.legs[0].origin.id);
278+
url.searchParams.append('T', journey.legs[0].departure);
279+
url.searchParams.append('VH', journey.refreshToken);
280+
url.searchParams.append('ZS', journey.legs[journey.legs.length - 1].destination.id);
281+
url.searchParams.append('journeyOptions', '0');
282+
url.searchParams.append('journeyProducts', '1023');
283+
url.searchParams.append('optimize', '1');
284+
url.searchParams.append('returnurl', 'dbnavigator://');
289285
url.searchParams.append('shpCtx', shpCtx);
286+
290287
t.url = url.href;
291288
} else {
292289
t.url = null;

0 commit comments

Comments
 (0)