Unescape in history reader, the escaped chars that were written by history writer.

fix-message-formatting
Damian Minkov 12 years ago
parent 2482a0b91f
commit 965f6b6f59

@ -17,6 +17,7 @@
import net.java.sip.communicator.service.history.event.*;
import net.java.sip.communicator.service.history.records.*;
import org.apache.commons.lang3.*;
import org.w3c.dom.*;
/**
@ -688,6 +689,9 @@ static HistoryRecord filterByKeyword( NodeList propertyNodes,
// Get nested TEXT node's value
String nodeValue = nestedNode.getNodeValue();
// unescape xml chars, we have escaped when writing values
nodeValue = StringEscapeUtils.unescapeXml(nodeValue);
if(field != null && field.equals(nodeName))
{
targetNodeFound = true;

@ -12,6 +12,7 @@ Import-Package: org.osgi.framework,
net.java.sip.communicator.service.history.records,
com.google.common.escape,
com.google.common.xml,
org.apache.commons.lang3,
org.w3c.dom,
org.xml.sax,
javax.xml.parsers,

@ -91,6 +91,8 @@ public static Test suite()
new TestMsgHistoryService("writeRecords"));
suite.addTest(
new TestMsgHistoryService("readRecords"));
suite.addTest(
new TestMsgHistoryService("specialChars"));
suite.addTest(
new TestMsgHistoryService("writeRecordsToMultiChat"));
suite.addTest(
@ -194,7 +196,8 @@ public void setupContact()
mockBImOpSet.createMessage("test message word3" + Math.random()),
mockBImOpSet.createMessage("test message word4" + Math.random()),
mockBImOpSet.createMessage("test message word5" + Math.random()),
mockBImOpSet.createMessage("Hello \u0002World\u0002!")
mockBImOpSet.createMessage("Hello \u0002World\u0002!"),
mockBImOpSet.createMessage("less than < this, greater than > and an ampersand &")
};
}
@ -403,27 +406,34 @@ public void specialChars()
waitWrite(500);
mockBImOpSet.deliverMessage(TEST_CONTACT_NAME_1, messagesToSend[6]);
waitWrite(500);
historyService.purgeLocallyCachedHistories();
/**
* Must return exactly the last 3 messages
* Must return exactly the last 4 messages
*/
Collection<EventObject> rs
= msgHistoryService.findLast(testMetaContact, 3);
= msgHistoryService.findLast(testMetaContact, 4);
assertTrue("Nothing found 8", !rs.isEmpty());
List<String> msgs = getMessages(rs);
assertEquals("Messages must be 3", 3, msgs.size());
assertTrue("Message no found",
assertEquals("Messages must be 4", 4, msgs.size());
assertTrue("Message not found",
msgs.contains(messagesToSend[3].getContent()));
assertTrue("Message no found",
assertTrue("Message not found",
msgs.contains(messagesToSend[4].getContent()));
// For now we are stripping in history the special content chars
// in order to avoid breaking the history records in the xml
assertTrue("Message no found",
assertTrue("Message not found",
msgs.contains(XmlEscapers.xmlContentEscaper().escape(
messagesToSend[5].getContent())));
assertTrue("Message not found",
msgs.contains(messagesToSend[6].getContent()));
}
private static void waitWrite(long timeout)

Loading…
Cancel
Save