Bug 64098 - Whitespace in text not preserved if starting with tab character
Summary: Whitespace in text not preserved if starting with tab character
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: 4.1.1-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2020-01-25 22:29 UTC by J. Mathews
Modified: 2020-01-26 21:43 UTC (History)
0 users



Attachments
Junit test that fails (2.19 KB, text/plain)
2020-01-26 20:01 UTC, J. Mathews
Details
build.gradle file to run testcase (225 bytes, text/plain)
2020-01-26 20:03 UTC, J. Mathews
Details

Note You need to log in before you can comment on or make changes to this bug.
Description J. Mathews 2020-01-25 22:29:44 UTC
Leading/trailing whitespace is preserved only if leading or trailing character is a whitespace but fails to preserve if that chararter is a tab (\t). Tab characters get stripped in the generated Word document.

Here's a patch to XWPFRun.java in org.apache.poi.xwpf.usermodel package from poi-ooxml-4.1.1.jar.

*** XWPFRun.java
--- XWPFRun.java.orig
***************
*** 146,152 ****
       */
      static void preserveSpaces(XmlString xs) {
          String text = xs.getStringValue();
!         if (text != null && text.length() >= 1 && (Character.isWhitespace(text.charAt(0)) 
! 											|| Character.isWhitespace(text.charAt(text.length()-1))) {
              XmlCursor c = xs.newCursor();
              c.toNextToken();
--- 146,152 ----
       */
      static void preserveSpaces(XmlString xs) {
          String text = xs.getStringValue();
!         if (text != null && (text.startsWith(" ") || text.endsWith(" "))) {
              XmlCursor c = xs.newCursor();
              c.toNextToken();
Comment 1 PJ Fanning 2020-01-26 14:35:27 UTC
Do you have an input file that demonstrates the problem? Or a unit test? It would be useful for us to have a regression test so that we don't accidentally undo this change later.
Comment 2 J. Mathews 2020-01-26 20:01:48 UTC
Created attachment 36981 [details]
Junit test that fails
Comment 3 J. Mathews 2020-01-26 20:03:11 UTC
Created attachment 36982 [details]
build.gradle file to run testcase
Comment 4 PJ Fanning 2020-01-26 21:43:59 UTC
applied with https://svn.apache.org/repos/asf/poi/trunk@1873188