Skip to content

Commit d78b728

Browse files
author
Bart Schuller
committed
Fix PIs appearing before text nodes.
The SAX handler that's used when you call loadXML didn't append the text buffer to the current node list before pushing a processing-instruction node.
1 parent 28bcf51 commit d78b728

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/main/scala/scala/xml/parsing/FactoryAdapter.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
189189
* Processing instruction.
190190
*/
191191
override def processingInstruction(target: String, data: String) {
192+
captureText()
192193
hStack pushAll createProcInstr(target, data)
193194
}
194195
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package scala.xml.parsing
2+
3+
import org.junit.Test
4+
import org.junit.Ignore
5+
import org.junit.runner.RunWith
6+
import org.junit.runners.JUnit4
7+
import scala.xml.JUnitAssertsForXML.assertEquals
8+
9+
class PiParsingTest {
10+
11+
12+
import scala.io.Source.fromString
13+
import scala.xml.parsing.ConstructingParser.fromSource
14+
import scala.xml.TopScope
15+
private def parse(s:String) = fromSource(fromString(s), preserveWS = true).element(TopScope)
16+
private def parseNoWS(s:String) = fromSource(fromString(s), preserveWS = false).element(TopScope)
17+
18+
@Test
19+
def piNoWSparse: Unit = {
20+
val expected = "<foo>a<?pi?>b</foo>"
21+
assertEquals(expected, parseNoWS("<foo>a<?pi?>b</foo>"))
22+
}
23+
24+
@Test
25+
def piNoWSLiteral: Unit = {
26+
val expected = "<foo>a<?pi?>b</foo>"
27+
assertEquals(expected, <foo>a<?pi?>b</foo>)
28+
}
29+
30+
@Test
31+
def piNoWSloadString: Unit = {
32+
val expected = "<foo>a<?pi?>b</foo>"
33+
assertEquals(expected, xml.XML.loadString("<foo>a<?pi?>b</foo>"))
34+
}
35+
36+
@Test
37+
def piParse: Unit = {
38+
val expected = "<foo> a <?pi?> b </foo>"
39+
assertEquals(expected, parse("<foo> a <?pi?> b </foo>"))
40+
}
41+
42+
@Test
43+
def piLoadString: Unit = {
44+
val expected = "<foo> a <?pi?> b </foo>"
45+
assertEquals(expected, xml.XML.loadString("<foo> a <?pi?> b </foo>"))
46+
}
47+
@Test
48+
def piLiteral: Unit = {
49+
val expected = "<foo> a <?pi?> b </foo>"
50+
assertEquals(expected, <foo> a <?pi?> b </foo>)
51+
}
52+
53+
}

0 commit comments

Comments
 (0)