Skip to content

Commit 04a2613

Browse files
committed
Change regex to more strict defintion.
1 parent 35a1c01 commit 04a2613

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/infra/y-redis/helper.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ export interface RoomStreamInfos {
2626
room: string;
2727
docid: string;
2828
}
29-
export const decodeRedisRoomStreamName = (rediskey: string, expectedPrefix: string): RoomStreamInfos => {
30-
const match = /^(.*):room:(.*):(.*)$/.exec(rediskey);
31-
if (match == null || match[1] !== expectedPrefix) {
32-
throw new Error(
33-
`Malformed stream name! prefix="${match?.[1]}" expectedPrefix="${expectedPrefix}", rediskey="${rediskey}"`,
34-
);
29+
30+
export const decodeRedisRoomStreamName = (rediskey: string, expectedRedisPrefix: string): RoomStreamInfos => {
31+
const match = new RegExp(`^${expectedRedisPrefix}:room:([^:]+):([^:]+)$`).exec(rediskey);
32+
console.log('match', match);
33+
console.log('expectedRedisPrefix', expectedRedisPrefix);
34+
35+
if (match == null) {
36+
throw new Error(`Malformed stream name! expectedRedisPrefix="${expectedRedisPrefix}", rediskey="${rediskey}"`);
3537
}
3638

37-
return { room: decodeURIComponent(match[2]), docid: decodeURIComponent(match[3]) };
39+
return { room: decodeURIComponent(match[1]), docid: decodeURIComponent(match[2]) };
3840
};
3941

4042
const getIdFromLastStreamMessageReply = (docStreamReplay: StreamMessagesReply): RedisKey | undefined => {

0 commit comments

Comments
 (0)