diff options
Diffstat (limited to 'poi')
-rw-r--r-- | poi/src/main/java/org/apache/poi/hssf/usermodel/HeaderFooter.java | 11 | ||||
-rw-r--r-- | poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java | 16 | ||||
-rw-r--r-- | poi/src/test/java9/module-info.class | bin | 4198 -> 4145 bytes |
3 files changed, 22 insertions, 5 deletions
diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HeaderFooter.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HeaderFooter.java index 9d369ad378..aa883dd44e 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HeaderFooter.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HeaderFooter.java @@ -298,10 +298,13 @@ public abstract class HeaderFooter implements org.apache.poi.ss.usermodel.Header // Now do the tricky, dynamic ones // These are things like font sizes, font names and colours - text = text.replaceAll("\\&\\d+", ""); - text = text.replaceAll("\\&\".*?,.*?\"", ""); - text = text.replaceAll("\\&K[\\dA-F]{6}", ""); - text = text.replaceAll("\\&K[\\d]{2}[+][\\d]{3}", ""); + text = text.replaceAll("&\\d+", ""); + text = text.replaceAll("&\".*?,.*?\"", ""); + text = text.replaceAll("&K[\\dA-F]{6}", ""); + text = text.replaceAll("&K[\\d]{2}[+][\\d]{3}", ""); + + text = text.replaceAll("&&", "&"); + // All done return text; diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java index 22ee32af31..b703390585 100644 --- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java +++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFHeaderFooter.java @@ -69,7 +69,7 @@ final class TestHSSFHeaderFooter { assertEquals(simple, HSSFHeader.stripFields(withPage)); assertEquals(simple, HSSFHeader.stripFields(withLots)); assertEquals(simple, HSSFHeader.stripFields(withFont)); - assertEquals(simple + "&&", HSSFHeader.stripFields(withOtherAnds)); + assertEquals(simple + "&", HSSFHeader.stripFields(withOtherAnds)); assertEquals(simple + "&a&b", HSSFHeader.stripFields(withOtherAnds2)); // Now test the default strip flag @@ -192,4 +192,18 @@ final class TestHSSFHeaderFooter { assertEquals("bar", footer2.getCenter()); } } + + @Test + void testHeaderWithAmpersand() throws IOException { + try (HSSFWorkbook wb = openSampleWorkbook("AmpersandHeader.xls")) { + HSSFSheet s = wb.getSheetAt(0); + HSSFHeader h = s.getHeader(); + String header = h.getCenter(); + assertEquals("one && two &&&&", header); + + // In Excel headers fields start with '&' + // For '&' to appear as text it needs to be escaped as '&&' + assertEquals("one & two &&", HSSFHeader.stripFields(header)); + } + } } diff --git a/poi/src/test/java9/module-info.class b/poi/src/test/java9/module-info.class Binary files differindex 438e778ab5..028b943d0a 100644 --- a/poi/src/test/java9/module-info.class +++ b/poi/src/test/java9/module-info.class |