Skip to content

Commit 8d847d3

Browse files
[verified] fix(desktop): validate persisted pinned-thread titles
Signed-off-by: Empire Operating <[email protected]>
1 parent 65f775e commit 8d847d3

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎desktop/src/features/channels/threadRailStorage.test.mjs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,23 @@ test("renames a pin locally, bounds its title, and clears it without changing id
248248
);
249249
});
250250

251+
test("parse normalizes persisted custom titles and rejects non-string titles", () => {
252+
const parsed = parseThreadRailStore({
253+
version: 1,
254+
collapsed: false,
255+
pins: [
256+
{ ...PIN_A, customTitle: ` ${"T".repeat(140)} ` },
257+
{ ...PIN_B, customTitle: {} },
258+
{ ...PIN_B, channelId: "channel-c", customTitle: " " },
259+
],
260+
});
261+
262+
assert.deepEqual(parsed?.pins, [
263+
{ ...PIN_A, customTitle: "T".repeat(128) },
264+
{ ...PIN_B, channelId: "channel-c" },
265+
]);
266+
});
267+
251268
test("write failure leaves the caller-owned in-memory store usable", () => {
252269
const original = window.localStorage.setItem;
253270
window.localStorage.setItem = () => {

‎desktop/src/features/channels/threadRailStorage.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ function normalizeExpandedReplyIds(value: unknown): string[] {
6767
return ids;
6868
}
6969

70+
function normalizeCustomTitle(value: unknown): string | undefined {
71+
if (typeof value !== "string") return undefined;
72+
const title = value.trim().slice(0, MAX_THREAD_RAIL_CUSTOM_TITLE_LENGTH);
73+
return title || undefined;
74+
}
75+
7076
function isPin(value: unknown): value is ThreadRailPin {
7177
if (typeof value !== "object" || value === null) return false;
7278
const pin = value as Record<string, unknown>;
@@ -80,6 +86,7 @@ function isPin(value: unknown): value is ThreadRailPin {
8086
typeof pin.pinnedAt === "number" &&
8187
Number.isFinite(pin.pinnedAt) &&
8288
pin.pinnedAt >= 0 &&
89+
(pin.customTitle === undefined || typeof pin.customTitle === "string") &&
8390
(pin.channelName === undefined || typeof pin.channelName === "string") &&
8491
(pin.rootExcerpt === undefined || typeof pin.rootExcerpt === "string")
8592
);
@@ -95,15 +102,18 @@ function samePin(
95102
function normalizePin(pin: ThreadRailPin): ThreadRailPin {
96103
const {
97104
channelName,
105+
customTitle,
98106
expandedReplyIds,
99107
returnAnchorId,
100108
rootExcerpt,
101109
...base
102110
} = pin;
103111
const normalizedExpandedReplyIds =
104112
normalizeExpandedReplyIds(expandedReplyIds);
113+
const normalizedCustomTitle = normalizeCustomTitle(customTitle);
105114
return {
106115
...base,
116+
...(normalizedCustomTitle ? { customTitle: normalizedCustomTitle } : {}),
107117
...(returnAnchorId
108118
? { returnAnchorId: returnAnchorId.slice(0, MAX_THREAD_RAIL_ID_LENGTH) }
109119
: {}),

‎desktop/src/features/channels/useThreadRail.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ export function useThreadRail(
8686
setRailState((current) => {
8787
if (current.scopeKey !== currentScopeKey) return current;
8888
const store = update(current.store);
89+
if (store === current.store) return current;
8990
writeThreadRailStore(scope, store);
90-
return store === current.store ? current : { ...current, store };
91+
return { ...current, store };
9192
});
9293
},
9394
[currentScopeKey, scope],

0 commit comments

Comments
 (0)