Fix XWPFDocument FindAndReplaceTextInParagraph#1524
Conversation
|
Please add at least one unit test for this fix. |
|
Added test which cover bug demo case and a bit more variations. |
|
I'm just realized that this method will not work when there are more than 2 occurance of replace text in paragraph. Will modify code and test for it. Idk if original method handle this or not. |
…of oldValue in paragraph. Modified test to check it.
|
Now must work properly. |
|
Btw, where are you from? |
|
Russia |
|
Unit tests failed. Please fix them |
|
I screwed up a bit with the number of commits. The tests passed successfully on my computer. But as I understood, the error was that the text contained foreign characters, and the file was not in utf8 encoding. If you want I can make new PR with single commit. |
|
Let me know if there's anything else you need me to do. |
There was a problem hiding this comment.
Pull Request Overview
This PR addresses issue #666 by fixing the FindAndReplaceTextInParagraph functionality in XWPFDocument, as well as adding a test case to validate the replacement behavior.
- Fixes text replacement within paragraphs in XWPFDocument.
- Adds a new test case to verify that FindAndReplaceTextInParagraph works as expected.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| testcases/ooxml/XWPF/UserModel/TestXWPFDocument.cs | Added a new test case to validate the updated FindAndReplaceText functionality. |
| ooxml/XWPF/Usermodel/XWPFDocument.cs | Updated the FindAndReplaceTextInParagraph internal method to support recursive replacements using an additional parameter. |
Comments suppressed due to low confidence (1)
ooxml/XWPF/Usermodel/XWPFDocument.cs:1895
- [nitpick] The variable 'firstParagraph' (and similarly 'lastParagraph') may be misleading as it actually represents a run index rather than a paragraph index. Consider renaming them to 'firstRunIndex' and 'lastRunIndex' for improved clarity.
int firstParagraph = -1;
| XWPFDocument outputDocument = outputDocument = XWPFTestDataSamples.WriteOutAndReadBack(doc); | ||
|
|
There was a problem hiding this comment.
Duplicate assignment to outputDocument detected. Please remove the redundant assignment to ensure clarity.
| XWPFDocument outputDocument = outputDocument = XWPFTestDataSamples.WriteOutAndReadBack(doc); | |
| XWPFDocument outputDocument = XWPFTestDataSamples.WriteOutAndReadBack(doc); |
|
Can you help solve the conflict? |
|
Wow, copilot review..... awesome! |
|
Solved conflict and applied copilot suggestions. |
|
LGTM |
My first attempt to contribute to NPOI.
Trying to fix my issue from 2021 #666. Work well for demo with bug and also passing single test in repo (FindAndReplaceText method).