Bug 62779

Summary: Paragraph text search results start with an error marker.
Product: POI Reporter: zhangfugui <1042126743>
Component: XWPFAssignee: POI Developers List <dev>
Status: NEEDINFO ---    
Severity: normal    
Priority: P2    
Version: 4.0.0-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Fix the sample

Description zhangfugui 2018-09-30 02:05:41 UTC
Created attachment 36177 [details]
Fix the sample

Fix paragraph text search results start point marking error.

##src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
Each loop of rArray in the searchText method causes beginTextPos and beginCharPos to be reset accordingly. The resulting TextSegment returns invalid data.

Such as:
Search ${code} in Runs data ["code:${", "code","}"].
The correct result returned should be

### start
startRun 0
startText 0
startChar 5
### end
endRun 2
endText 0
endChar 0
But the actual interior only retains the startRun state, and startText, startChar are reset at each loop.

startRun 0
startText 0
startChar 0
Comment 1 PJ Fanning 2018-09-30 08:14:02 UTC
Would you be able to provide a test case? Something that reads an input docx and that does a searchText call that fails with existing code but that passes with your change.

A few existing tests can be found in:

https://github.com/apache/poi/blob/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java