1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 03:52:06 +01:00

[websocket] Improve handling of expanded 'open' element

Prior to this fix, Smack requires the 'open' element send on a websocket connection to be collapsed. With the change in
this commit, an expanded (eg: `<open ...></open>`) element can also be used.

fixes SMACK-935
This commit is contained in:
Guus der Kinderen 2023-10-27 13:27:29 +02:00
parent c7f3e231d0
commit 6244a213c8
2 changed files with 7 additions and 3 deletions

View file

@ -95,7 +95,9 @@ public abstract class AbstractWebSocket {
static String getStreamFromOpenElement(String openElement) { static String getStreamFromOpenElement(String openElement) {
String streamElement = openElement.replaceFirst("\\A<open ", "<stream:stream ") String streamElement = openElement.replaceFirst("\\A<open ", "<stream:stream ")
.replace("urn:ietf:params:xml:ns:xmpp-framing", "jabber:client") .replace("urn:ietf:params:xml:ns:xmpp-framing", "jabber:client")
.replaceFirst("/>\\s*\\z", " xmlns:stream='http://etherx.jabber.org/streams'>"); .replaceFirst("/>\\s*\\z", " xmlns:stream='http://etherx.jabber.org/streams'>")
.replaceFirst("></open>\\s*\\z", " xmlns:stream='http://etherx.jabber.org/streams'>");
return streamElement; return streamElement;
} }

View file

@ -24,18 +24,20 @@ import org.junit.jupiter.api.Test;
public final class AbstractWebSocketTest { public final class AbstractWebSocketTest {
private static final String OPEN_ELEMENT = "<open from='localhost.org' id='aov9ihhmmn' xmlns='urn:ietf:params:xml:ns:xmpp-framing' xml:lang='en' version='1.0'/>"; private static final String OPEN_ELEMENT = "<open from='localhost.org' id='aov9ihhmmn' xmlns='urn:ietf:params:xml:ns:xmpp-framing' xml:lang='en' version='1.0'/>";
private static final String OPEN_ELEMENT_EXPANDED = "<open from='localhost.org' id='aov9ihhmmn' xmlns='urn:ietf:params:xml:ns:xmpp-framing' xml:lang='en' version='1.0'></open>";
private static final String OPEN_STREAM = "<stream:stream from='localhost.org' id='aov9ihhmmn' xmlns='jabber:client' xml:lang='en' version='1.0' xmlns:stream='http://etherx.jabber.org/streams'>"; private static final String OPEN_STREAM = "<stream:stream from='localhost.org' id='aov9ihhmmn' xmlns='jabber:client' xml:lang='en' version='1.0' xmlns:stream='http://etherx.jabber.org/streams'>";
private static final String CLOSE_ELEMENT = "<close xmlns='urn:ietf:params:xml:ns:xmpp-framing'/>"; private static final String CLOSE_ELEMENT = "<close xmlns='urn:ietf:params:xml:ns:xmpp-framing'/>";
@Test @Test
public void getStreamFromOpenElementTest() { public void getStreamFromOpenElementTest() {
String generatedOpenStream = AbstractWebSocket.getStreamFromOpenElement(OPEN_ELEMENT); assertEquals(OPEN_STREAM, AbstractWebSocket.getStreamFromOpenElement(OPEN_ELEMENT));
assertEquals(generatedOpenStream, OPEN_STREAM); assertEquals(OPEN_STREAM, AbstractWebSocket.getStreamFromOpenElement(OPEN_ELEMENT_EXPANDED));
} }
@Test @Test
public void isOpenElementTest() { public void isOpenElementTest() {
assertTrue(AbstractWebSocket.isOpenElement(OPEN_ELEMENT)); assertTrue(AbstractWebSocket.isOpenElement(OPEN_ELEMENT));
assertTrue(AbstractWebSocket.isOpenElement(OPEN_ELEMENT_EXPANDED));
assertFalse(AbstractWebSocket.isOpenElement(OPEN_STREAM)); assertFalse(AbstractWebSocket.isOpenElement(OPEN_STREAM));
} }