elharo opened a new pull request, #139:
URL: https://github.com/apache/xerces-j/pull/139

   ## Summary
   
   Fixes [XERCESJ-1694](https://issues.apache.org/jira/browse/XERCESJ-1694).
   
   When an `xi:include` uses an `xpointer` to select a fragment of another 
resource, `XIncludeHandler` creates an `XPointerParserConfiguration` for the 
included resource. That configuration contained both an `XIncludeHandler` and 
an `XPointerHandler`, wired as:
   
   ```
   parser -> XIncludeHandler -> XPointerHandler -> application
   ```
   
   The `XIncludeHandler` therefore expanded every include in the included 
resource *before* the `XPointerHandler` could select the requested fragment. 
With two resources that include each other, this recurses without bound, even 
when the XPointer selects a fragment that does not contain the include. For 
example, parsing `a.xml`:
   
   ```xml
   <book ...>
     ...
     <xi:include href="b.xml" xpointer="b-chapter"/>
   </book>
   ```
   
   where `b.xml` includes `a.xml` again causes a `StackOverflowError`.
   
   ## Fix
   
   `XPointerHandler` already extends `XIncludeHandler`, so it can process 
includes inside the selected fragment itself. `XPointerParserConfiguration` now 
uses the `XPointerHandler` as the only include-related component in the 
pipeline:
   
   ```
   parser -> XPointerHandler -> application
   ```
   
   The XPointer filter runs first, so includes outside the selected fragment 
are ignored (and cannot recurse), while includes inside the selected fragment 
are still expanded.
   
   ## Tests
   
   Added `tests/xinclude/XPointerIncludeCycleTest.java` plus test resources 
(`xpointer-cycle-a.xml`, `-b.xml`, `-c.xml`). The test parses 
mutually-including documents with an `XPointerParserConfiguration`-based 
pipeline and verifies that:
   
   * only the original `a-chapter` and the selected `b-chapter` are present (no 
recursion), and
   * an include nested inside the selected fragment is still expanded.
   
   The test fails with a `StackOverflowError` before the fix and passes after 
it. The full `ant test` suite passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to