Skip to content

Commit 98523ef

Browse files
author
kishansomaiya
committed
fix(colibris): keep recent pad names readable, encode only navigation URL (#7865)
1 parent c4780a8 commit 98523ef

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

src/static/js/pad_userlist.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ const chat = require('./chat').chat;
2323
import html10n from './vendors/html10n';
2424
let myUserInfo = {};
2525

26+
const decodePadSegment = (segment: string): string => {
27+
try {
28+
return decodeURIComponent(segment);
29+
} catch {
30+
return segment;
31+
}
32+
};
33+
2634
let colorPickerOpen = false;
2735
let colorPickerSetup = false;
2836

@@ -557,7 +565,7 @@ const paduserlist = (() => {
557565
if (localStorage.getItem('recentPads') != null) {
558566
const recentPadsList = JSON.parse(localStorage.getItem('recentPads'));
559567
const pathSegments = window.location.pathname.split('/');
560-
const padName = pathSegments[pathSegments.length - 1];
568+
const padName = decodePadSegment(pathSegments[pathSegments.length - 1]);
561569
const existingPad = recentPadsList.find((pad) => pad.name === padName);
562570
if (existingPad) {
563571
existingPad.members = online;

src/static/skins/colibris/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
'use strict';
22

3+
const decodePadName = (name) => {
4+
try {
5+
return decodeURIComponent(name);
6+
} catch {
7+
return name;
8+
}
9+
};
10+
311
window.addEventListener('pageshow', (event) => {
412
if (event.persisted) {
513
if (document.readyState === 'complete' || document.readyState === 'interactive') {
@@ -37,6 +45,13 @@ window.customStart = () => {
3745
recentPadListData = JSON.parse(recentPadsFromLocalStorage);
3846
}
3947

48+
// Normalize older entries that stored encoded names (e.g. Test%2F123).
49+
recentPadListData = recentPadListData.map((pad) => ({
50+
...pad,
51+
name: decodePadName(String(pad.name ?? '')),
52+
}));
53+
localStorage.setItem('recentPads', JSON.stringify(recentPadListData));
54+
4055
// Remove duplicates based on pad name and sort by timestamp
4156
recentPadListData = recentPadListData.filter(
4257
(pad, index, self) => index === self.findIndex((p) => p.name === pad.name)
@@ -70,7 +85,7 @@ window.customStart = () => {
7085
li.style.cursor = 'pointer';
7186

7287
li.className = 'recent-pad';
73-
const padPath = `${window.location.href}p/${pad.name}`;
88+
const padPath = `${window.location.href}p/${encodeURIComponent(pad.name)}`;
7489
const link = document.createElement('a');
7590
link.style.textDecoration = 'none';
7691

src/static/skins/colibris/pad.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
'use strict';
22

33
const MAX_PADS_IN_HISTORY = 3;
4+
const decodePadSegment = (segment) => {
5+
try {
6+
return decodeURIComponent(segment);
7+
} catch {
8+
return segment;
9+
}
10+
};
411

512
window.customStart = () => {
613
$('#pad_title').show();
714
$('.buttonicon').on('mousedown', function () { $(this).parent().addClass('pressed'); });
815
$('.buttonicon').on('mouseup', function () { $(this).parent().removeClass('pressed'); });
916

1017
const pathSegments = window.location.pathname.split('/');
11-
const padName = pathSegments[pathSegments.length - 1];
18+
const padName = decodePadSegment(pathSegments[pathSegments.length - 1]);
1219
const recentPads = localStorage.getItem('recentPads');
1320
if (recentPads == null) {
1421
localStorage.setItem('recentPads', JSON.stringify([]));

0 commit comments

Comments
 (0)