Commit fd821670 authored by Christian Schudt's avatar Christian Schudt

OF-839 Forwarded extension should not overwrite extension namespaces of the forwarded message.

parent 2743c92c
......@@ -19,7 +19,10 @@ public class Forwarded extends PacketExtension {
for (Object element : copy.getElement().elements()) {
if (element instanceof Element) {
Element el = (Element) element;
el.setQName(QName.get(el.getName(), "jabber:client"));
// Only set the "jabber:client" namespace if the namespace is empty (otherwise the resulting xml would look like <body xmlns=""/>)
if ("".equals(el.getNamespace().getStringValue())) {
el.setQName(QName.get(el.getName(), "jabber:client"));
}
}
}
element.add(copy.getElement());
......
package org.jivesoftware.openfire.forward;
import org.junit.Test;
import org.xmpp.forms.DataForm;
import org.xmpp.packet.Message;
import static org.junit.Assert.assertEquals;
......@@ -15,12 +16,13 @@ public class ForwardTest {
Message message = new Message();
message.setType(Message.Type.chat);
message.setBody("Tests");
message.addExtension(new DataForm(DataForm.Type.submit));
Forwarded forwarded = new Forwarded(message);
Forwarded forwarded2 = new Forwarded(message);
String xml1 = forwarded.getElement().asXML();
String xml2 = forwarded2.getElement().asXML();
assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body></message></forwarded>", xml1);
assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body></message></forwarded>", xml2);
assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body><x xmlns=\"jabber:x:data\" type=\"submit\"/></message></forwarded>", xml1);
assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body><x xmlns=\"jabber:x:data\" type=\"submit\"/></message></forwarded>", xml2);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment