diff --git a/src/fr/devinsy/xidyn/utils/XidynUtils.java b/src/fr/devinsy/xidyn/utils/XidynUtils.java index 5e31b4d..a6f5eb1 100644 --- a/src/fr/devinsy/xidyn/utils/XidynUtils.java +++ b/src/fr/devinsy/xidyn/utils/XidynUtils.java @@ -31,7 +31,7 @@ import org.xml.sax.SAXException; public class XidynUtils { static private final Logger logger = LoggerFactory.getLogger(XidynUtils.class); - private static final Pattern BODY_PATTERN = Pattern.compile("^.*<[bB][oO][dD][yY]>\\s*(.*\\S)\\s*[bB][oO][dD][yY]>.*$"); + private static final Pattern BODY_PATTERN = Pattern.compile("(?s)^.*<[bB][oO][dD][yY]>\\s*(\\S.*\\S)\\s*[bB][oO][dD][yY]>.*$"); /** * This method adds a tag to a DOM object. @@ -41,18 +41,21 @@ public class XidynUtils // Find head tag. Node headNode = findHeadNode(doc); + logger.debug("headNode = [" + headNode + "]"); + if (headNode != null) + { + Node metaNode = doc.createElement("meta"); - Node metaNode = doc.createElement("meta"); + NamedNodeMap attrMap = metaNode.getAttributes(); + Node attrNode = doc.createAttribute("name"); + attrMap.setNamedItem(attrNode); + attrNode.setNodeValue(name); - NamedNodeMap attrMap = metaNode.getAttributes(); - Node attrNode = doc.createAttribute("name"); - attrMap.setNamedItem(attrNode); - attrNode.setNodeValue(name); - - attrNode = doc.createAttribute("content"); - attrMap.setNamedItem(attrNode); - attrNode.setNodeValue(content); - headNode.insertBefore(metaNode, headNode.getFirstChild()); + attrNode = doc.createAttribute("content"); + attrMap.setNamedItem(attrNode); + attrNode.setNodeValue(content); + headNode.insertBefore(metaNode, headNode.getFirstChild()); + } } /** diff --git a/test/fr/devinsy/xidyn/utils/XidynUtilsTest.java b/test/fr/devinsy/xidyn/utils/XidynUtilsTest.java index 2ca9bd7..069b608 100644 --- a/test/fr/devinsy/xidyn/utils/XidynUtilsTest.java +++ b/test/fr/devinsy/xidyn/utils/XidynUtilsTest.java @@ -52,7 +52,7 @@ public class XidynUtilsTest @Test public void testExtractBodyContent03() { - String source = "aaaaa
zzzzz"; + String source = "aaaaazzzzz"; String target = XidynUtils.extractBodyContent(source); Assertions.assertThat(target).isEqualTo(""); @@ -64,12 +64,41 @@ public class XidynUtilsTest @Test public void testExtractBodyContent04() { - String source = "aaaaa hello zzzzz"; + String source = "aaaaa hello zzzzz"; String target = XidynUtils.extractBodyContent(source); Assertions.assertThat(target).isEqualTo("hello"); } + /** + * + */ + @Test + public void testExtractBodyContent05() + { + StringBuffer buffer = new StringBuffer(1000); + buffer.append("").append("\n"); + buffer.append("").append("\n"); + buffer.append("").append("\n"); + buffer.append("").append("\n"); + buffer.append("