From db0124f896d4a1e16776ca31c5c0d6cbc3f6ef88 Mon Sep 17 00:00:00 2001 From: Naoki Ishikawa Date: Thu, 28 Nov 2024 16:56:12 +0900 Subject: [PATCH] Fixed a problem that connection from Socket.IO Client v2 failed. The cause is an error in the skip range of the index of the frame. --- .../socketio/protocol/PacketDecoder.java | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/corundumstudio/socketio/protocol/PacketDecoder.java b/src/main/java/com/corundumstudio/socketio/protocol/PacketDecoder.java index 914a272c..1f9c70e3 100644 --- a/src/main/java/com/corundumstudio/socketio/protocol/PacketDecoder.java +++ b/src/main/java/com/corundumstudio/socketio/protocol/PacketDecoder.java @@ -307,23 +307,18 @@ private String readNamespace(ByteBuf frame, final boolean defaultToAll) { */ ByteBuf buffer = frame.slice(); + int namespaceFieldEndIndex = buffer.bytesBefore((byte) ','); + namespaceFieldEndIndex = namespaceFieldEndIndex > 0 ? namespaceFieldEndIndex : buffer.readableBytes(); - int endIndex = buffer.bytesBefore((byte) '?'); - if (endIndex > 0) { - String namespace = readString(buffer, endIndex); - if(namespace.startsWith("/")) { - frame.skipBytes(endIndex + 1); - return namespace; - } - } - endIndex = buffer.bytesBefore((byte) ','); - if (endIndex > 0) { - String namespace = readString(buffer, endIndex); - if(namespace.startsWith("/")) { - frame.skipBytes(endIndex + 1); - return namespace; - } + int namespaceEndIndex = buffer.bytesBefore((byte) '?'); + namespaceEndIndex = namespaceEndIndex > 0 ? namespaceEndIndex : namespaceFieldEndIndex; + + String namespace = readString(buffer, namespaceEndIndex); + if (namespace.startsWith("/")) { + frame.skipBytes(namespaceFieldEndIndex + 1); + return namespace; } + if (defaultToAll) { // skip this frame frame.skipBytes(frame.readableBytes());