aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2024-08-14 17:38:32 +0000
committerPJ Fanning <fanningpj@apache.org>2024-08-14 17:38:32 +0000
commit33260d51ee371ea213368393ea82af20aeea5fe1 (patch)
tree30c4c8b876366b37359a37b2770e1079901caad7
parent6c56c2d00fdc3aefaaeeac9ff4fb117d0e0a688a (diff)
downloadpoi-33260d51ee371ea213368393ea82af20aeea5fe1.tar.gz
poi-33260d51ee371ea213368393ea82af20aeea5fe1.zip
[github-670] XWPFRun.getText should support delInstrText and noBreakHyphen. Thanks to fangd1997. This closes #670
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1919895 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java7
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFRun.java11
2 files changed, 16 insertions, 2 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
index 481e5ba8d2..ca95740fe8 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
@@ -1521,10 +1521,10 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
if (o instanceof CTText) {
final Node node = o.getDomNode();
- // Field Codes (w:instrText, defined in spec sec. 17.16.23)
+ // Field Codes (w:instrText, defined in spec sec. 17.16.23 and w:delInstrText, defined in spec sec. 17.16.13)
// come up as instances of CTText, but we don't want them
// in the normal text output
- if (!("instrText".equals(node.getLocalName()) && XSSFRelation.NS_WORDPROCESSINGML.equals(node.getNamespaceURI()))) {
+ if (!(("instrText".equals(node.getLocalName()) || "delInstrText".equals(node.getLocalName())) && XSSFRelation.NS_WORDPROCESSINGML.equals(node.getNamespaceURI()))) {
String textValue = ((CTText) o).getStringValue();
if (textValue != null) {
if (isCapitalized() || isSmallCaps()) {
@@ -1564,6 +1564,9 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
final Node node = o.getDomNode();
if (XSSFRelation.NS_WORDPROCESSINGML.equals(node.getNamespaceURI())) {
switch (node.getLocalName()) {
+ case "noBreakHyphen":
+ text.append('‑');
+ break;
case "tab":
text.append('\t');
break;
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFRun.java b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
index eee37446e1..c9c199429c 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
@@ -99,6 +99,17 @@ class TestXWPFRun {
//fail("Position wrong");
}
+ @Test
+ void testGetTextWithNoBreakHyphen() {
+ ctRun.addNewT().setStringValue("TEST STRING 1");
+ ctRun.addNewInstrText().setStringValue("InstrText");
+ ctRun.addNewNoBreakHyphen();
+ ctRun.addNewDelInstrText().setStringValue("DelInstrText");
+ ctRun.addNewT().setStringValue("1");
+ XWPFRun run = new XWPFRun(ctRun, irb);
+ assertEquals("TEST STRING 1‑1", run.text());
+ }
+
/*
* bug 59208
* Purpose: test all valid boolean-like values