Skip to content

Commit 2e242d0

Browse files
authored
website: timetables: Re-fix deserialization of TA courses in share link (#4226)
The previous fix didn't work for courses with multiple lessons. Fix that case. Fixes #4171 again
1 parent 0f8cb97 commit 2e242d0

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

website/src/utils/timetables.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,5 +691,15 @@ describe(deserializeTa, () => {
691691
CS3210: [['Tutorial', '02']],
692692
CS3219: [['Tutorial', '15']],
693693
});
694+
expect(
695+
deserializeTa('?CS1010S=REC:1,TUT:8&ta=CS3210(TUT:02),CS3219(TUT:15),CS3211(LAB:B05,TUT:13)'),
696+
).toEqual({
697+
CS3210: [['Tutorial', '02']],
698+
CS3219: [['Tutorial', '15']],
699+
CS3211: [
700+
['Laboratory', 'B05'],
701+
['Tutorial', '13'],
702+
],
703+
});
694704
});
695705
});

website/src/utils/timetables.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,15 @@ export function deserializeTa(serialized: string): TaModulesConfig {
625625
// If user manually enters multiple TA query keys, use latest one
626626
const ta = Array.isArray(params.ta) ? last(params.ta) : params.ta;
627627
if (!ta) return deserialized;
628-
ta.split(LESSON_SEP).forEach((moduleConfig) => {
628+
ta.split(')').forEach((_moduleConfig) => {
629+
// Second and subsequent matches have a leading comma
630+
const moduleConfig = _moduleConfig.replace(/^,/, '');
629631
const moduleCodeMatches = moduleConfig.match(/(.*)\(/);
630632
if (moduleCodeMatches === null) {
631633
return;
632634
}
633635

634-
const lessonsMatches = moduleConfig.match(/\((.*)\)/);
636+
const lessonsMatches = moduleConfig.match(/\((.*)/);
635637
if (lessonsMatches === null) {
636638
return;
637639
}

0 commit comments

Comments
 (0)