Skip to content

Commit 7d0e442

Browse files
authored
Merge pull request #93 from ashawley/fix-44-si-9060-xml-5ed-names
Fix #44 SI-9060 XML 5th edition name characters
2 parents b0a753d + ee91a55 commit 7d0e442

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

jvm/src/test/scala/scala/xml/XMLTest.scala

+9-3
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class XMLTestJVM {
390390
}
391391

392392
@UnitTest
393-
def t5052 {
393+
def t5052 = {
394394
assertTrue(<elem attr={ null: String }/> xml_== <elem/>)
395395
assertTrue(<elem attr={ None }/> xml_== <elem/>)
396396
assertTrue(<elem/> xml_== <elem attr={ null: String }/>)
@@ -412,7 +412,7 @@ class XMLTestJVM {
412412
}
413413

414414
@UnitTest
415-
def t5843 {
415+
def t5843 = {
416416
val foo = scala.xml.Attribute(null, "foo", "1", scala.xml.Null)
417417
val bar = scala.xml.Attribute(null, "bar", "2", foo)
418418
val ns = scala.xml.NamespaceBinding(null, "uri", scala.xml.TopScope)
@@ -444,7 +444,7 @@ class XMLTestJVM {
444444
}
445445

446446
@UnitTest
447-
def t7074 {
447+
def t7074 = {
448448
assertEquals("""<a/>""", sort(<a/>) toString)
449449
assertEquals("""<a b="2" c="3" d="1"/>""", sort(<a d="1" b="2" c="3"/>) toString)
450450
assertEquals("""<a b="2" c="4" d="1" e="3" f="5"/>""", sort(<a d="1" b="2" e="3" c="4" f="5"/>) toString)
@@ -456,6 +456,12 @@ class XMLTestJVM {
456456
assertEquals("""<a a:b="1" a:c="2" a:d="3" a:e="4" a:f="5"/>""", sort(<a a:b="1" a:c="2" a:d="3" a:e="4" a:f="5"/>) toString)
457457
}
458458

459+
@UnitTest
460+
def t9060 = {
461+
val expected = """<a xmlns:b·="http://example.com"/>"""
462+
assertEquals(expected, XML.loadString(expected).toString)
463+
}
464+
459465
@UnitTest
460466
def attributes = {
461467
val noAttr = <t/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package scala.xml
2+
package parsing
3+
4+
import scala.io.Source
5+
import org.junit.Test
6+
import scala.xml.JUnitAssertsForXML.{ assertEquals => assertXml }
7+
8+
class ConstructingParserTest {
9+
10+
@Test
11+
def t9060 = {
12+
val a = """<a xmlns:b·="http://example.com"/>"""
13+
val source = new Source {
14+
val iter = a.iterator
15+
override def reportError(pos: Int, msg: String, out: java.io.PrintStream = Console.err) = {}
16+
}
17+
val doc = ConstructingParser.fromSource(source, false).content(TopScope)
18+
assertXml(a, doc)
19+
20+
}
21+
22+
}

shared/src/main/scala/scala/xml/parsing/TokenTests.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ trait TokenTests {
3737

3838
/**
3939
* {{{
40-
* NameChar ::= Letter | Digit | '.' | '-' | '_' | ':'
40+
* NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | #xB7
4141
* | CombiningChar | Extender
4242
* }}}
43-
* See [4] and Appendix B of XML 1.0 specification.
43+
* See [4] and [4a] of Appendix B of XML 1.0 specification.
4444
*/
4545
def isNameChar(ch: Char) = {
4646
import java.lang.Character._
@@ -50,19 +50,19 @@ trait TokenTests {
5050
case COMBINING_SPACING_MARK |
5151
ENCLOSING_MARK | NON_SPACING_MARK |
5252
MODIFIER_LETTER | DECIMAL_DIGIT_NUMBER => true
53-
case _ => ".-:" contains ch
53+
case _ => ".-:·" contains ch
5454
})
5555
}
5656

5757
/**
5858
* {{{
59-
* NameStart ::= ( Letter | '_' )
59+
* NameStart ::= ( Letter | '_' | ':' )
6060
* }}}
6161
* where Letter means in one of the Unicode general
6262
* categories `{ Ll, Lu, Lo, Lt, Nl }`.
6363
*
6464
* We do not allow a name to start with `:`.
65-
* See [3] and Appendix B of XML 1.0 specification
65+
* See [4] and Appendix B of XML 1.0 specification
6666
*/
6767
def isNameStart(ch: Char) = {
6868
import java.lang.Character._
@@ -71,7 +71,7 @@ trait TokenTests {
7171
case LOWERCASE_LETTER |
7272
UPPERCASE_LETTER | OTHER_LETTER |
7373
TITLECASE_LETTER | LETTER_NUMBER => true
74-
case _ => ch == '_'
74+
case _ => ":_".contains(ch)
7575
}
7676
}
7777

shared/src/test/scala/scala/xml/UtilityTest.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ package scala.xml
22

33
import org.junit.Test
44
import org.junit.Assert.assertTrue
5-
import org.junit.Assert.assertFalse
65
import org.junit.Assert.assertEquals
76

87
class UtilityTest {
98

109
@Test
1110
def isNameStart: Unit = {
1211
assertTrue(Utility.isNameStart('b'))
13-
assertFalse(Utility.isNameStart(':'))
12+
assertTrue(Utility.isNameStart(':'))
1413
}
1514

1615
@Test

0 commit comments

Comments
 (0)