fix: don't crash if event name is not a string

This commit is contained in:
Barış Soner Uşaklı
2023-03-27 10:38:53 -04:00
parent e9a8e19508
commit 37b48b82a4
2 changed files with 15 additions and 1 deletions

View File

@@ -120,7 +120,12 @@ async function onMessage(socket, payload) {
return winston.warn('[socket.io] Empty method name');
}
const parts = eventName.toString().split('.');
if (typeof eventName !== 'string') {
const escapedName = validator.escape(String(eventName));
return callback({ message: `[[error:invalid-event, ${escapedName}]]` });
}
const parts = eventName.split('.');
const namespace = parts[0];
const methodToCall = parts.reduce((prev, cur) => {
if (prev !== null && prev[cur] && (!prev.hasOwnProperty || prev.hasOwnProperty(cur))) {