You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by GitBox <gi...@apache.org> on 2023/01/09 21:36:14 UTC

[GitHub] [daffodil] stevedlawrence commented on a diff in pull request #905: Fix mixed content error in SAX unparse

stevedlawrence commented on code in PR #905:
URL: https://github.com/apache/daffodil/pull/905#discussion_r1065128493


##########
daffodil-core/src/test/scala/org/apache/daffodil/processor/TestSAXUnparseAPI.scala:
##########
@@ -100,6 +101,26 @@ class TestSAXUnparseAPI {
     assertEquals(testData, bao.toString)
   }
 
+  /**
+   * tests the case of unparsing with the namespace features/prefixes set to
+   * false/true, with non-empty prefixes and ignored attributes
+   */
+  @Test def testUnparseContentHandler_unparse_namespace_prefix_feature_non_empty_prefix(): Unit = {
+    val xmlReader: XMLReader = DaffodilSAXParserFactory().newSAXParser.getXMLReader
+    val bao = new ByteArrayOutputStream()
+    val wbc = java.nio.channels.Channels.newChannel(bao)
+    val unparseContentHandler = dp.newContentHandlerInstance(wbc)
+    xmlReader.setContentHandler(unparseContentHandler)
+    xmlReader.setFeature(XMLUtils.SAX_NAMESPACES_FEATURE, false)
+    xmlReader.setFeature(XMLUtils.SAX_NAMESPACE_PREFIXES_FEATURE, true)
+    val infoset = <p:list xmlns:p="http://example.com" ignored="attr"><p:w>9</p:w><p:w>1</p:w><p:w>0</p:w></p:list>
+    val bai = new ByteArrayInputStream(infoset.toString.getBytes)
+    xmlReader.parse(new InputSource(bai))
+    val ur = unparseContentHandler.getUnparseResult
+    assertTrue(!ur.isError)
+    assertEquals(testData, bao.toString)

Review Comment:
   `testData` comes from an `import TestSAXUtils._` at the top of the file. There's a number of TestSAX* files that do this to test the SAX API. It's definitely not very clear.
   
   This test case is actually to improve missing coverage that I found when was doing SAX performance stuff. The CI shows it adds about +.04% coverage.
   
   I actually have one more SAX related change in the works to refactor this SAX stuff a bit. It made sense we originally added it but I found it confusing coming back to this code years later to investigate performance. So while it was fresh in my mind I wanted to make the code more clear with more comments. I'll move this test to that PR, since it really has nothing to do with mixed content.



-- 
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: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org