DocumentBuilder fix: avoid spurious error and crash on <numPr><numId val="0" /></numPr> #182
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before DocumentBuilder modifies a document, it has an internal/private
TestForUnsupportedDocumentfunction that tests a document to see if it has unsupported features that DocumentBuilder doesn't support. However, there's a bug there. The function currently throws an error "Source {0} is invalid document - contains numbering markup but no numbering part", but it's checking the wrong thing before throwing it. See the commit below, which includes test files, unit tests, etc..At issue are "numbering properties" elements, which normally contain the ID of a numbering definition (located in a separate number definitions part of the docx), UNLESS the id == 0, in which case that is a way to explicitly say that the numbering properties do NOT reference a numbering definition.
It seems DocumentBuilder was originally written to handle , which is non-standard AFAIK. I've left that in there, but now handle the proper way to designate numId="0" as well. I also fixed up the logic in DocumentBuilder accordingly, so that it properly ignores numId == "0" instead of looking for a non-existing numbering part.
Lastly... regarding the changes in function CopyNumbering() in DocumentBuilder.cs... GitHub makes the changes below look more serious than they are, by failing to recognize that most of the changes were just in whitespace, because I changed the level of indentation across several dozen lines, because the level of indentation changed. I am half inclined to leave the unnecessary if test in there, just so the diffs don't look so confusing. But for now I removed the now-unnecessary if.