Skip to content

Fix #44 SI-9060 XML 5th edition name characters #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions jvm/src/test/scala/scala/xml/XMLTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ class XMLTestJVM {
}

@UnitTest
def t5052 {
def t5052 = {
assertTrue(<elem attr={ null: String }/> xml_== <elem/>)
assertTrue(<elem attr={ None }/> xml_== <elem/>)
assertTrue(<elem/> xml_== <elem attr={ null: String }/>)
Expand All @@ -412,7 +412,7 @@ class XMLTestJVM {
}

@UnitTest
def t5843 {
def t5843 = {
val foo = scala.xml.Attribute(null, "foo", "1", scala.xml.Null)
val bar = scala.xml.Attribute(null, "bar", "2", foo)
val ns = scala.xml.NamespaceBinding(null, "uri", scala.xml.TopScope)
Expand Down Expand Up @@ -444,7 +444,7 @@ class XMLTestJVM {
}

@UnitTest
def t7074 {
def t7074 = {
assertEquals("""<a/>""", sort(<a/>) toString)
assertEquals("""<a b="2" c="3" d="1"/>""", sort(<a d="1" b="2" c="3"/>) toString)
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)
Expand All @@ -456,6 +456,12 @@ class XMLTestJVM {
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)
}

@UnitTest
def t9060 = {
val expected = """<a xmlns:b·="http://example.com"/>"""
assertEquals(expected, XML.loadString(expected).toString)
}

@UnitTest
def attributes = {
val noAttr = <t/>
Expand Down
22 changes: 22 additions & 0 deletions jvm/src/test/scala/scala/xml/parsing/ConstructingParserTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package scala.xml
package parsing

import scala.io.Source
import org.junit.Test
import scala.xml.JUnitAssertsForXML.{ assertEquals => assertXml }

class ConstructingParserTest {

@Test
def t9060 = {
val a = """<a xmlns:b·="http://example.com"/>"""
val source = new Source {
val iter = a.iterator
override def reportError(pos: Int, msg: String, out: java.io.PrintStream = Console.err) = {}
}
val doc = ConstructingParser.fromSource(source, false).content(TopScope)
assertXml(a, doc)

}

}
12 changes: 6 additions & 6 deletions shared/src/main/scala/scala/xml/parsing/TokenTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ trait TokenTests {

/**
* {{{
* NameChar ::= Letter | Digit | '.' | '-' | '_' | ':'
* NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | #xB7
* | CombiningChar | Extender
* }}}
* See [4] and Appendix B of XML 1.0 specification.
* See [4] and [4a] of Appendix B of XML 1.0 specification.
*/
def isNameChar(ch: Char) = {
import java.lang.Character._
Expand All @@ -50,19 +50,19 @@ trait TokenTests {
case COMBINING_SPACING_MARK |
ENCLOSING_MARK | NON_SPACING_MARK |
MODIFIER_LETTER | DECIMAL_DIGIT_NUMBER => true
case _ => ".-:" contains ch
case _ => ".-:·" contains ch
})
}

/**
* {{{
* NameStart ::= ( Letter | '_' )
* NameStart ::= ( Letter | '_' | ':' )
* }}}
* where Letter means in one of the Unicode general
* categories `{ Ll, Lu, Lo, Lt, Nl }`.
*
* We do not allow a name to start with `:`.
* See [3] and Appendix B of XML 1.0 specification
* See [4] and Appendix B of XML 1.0 specification
*/
def isNameStart(ch: Char) = {
import java.lang.Character._
Expand All @@ -71,7 +71,7 @@ trait TokenTests {
case LOWERCASE_LETTER |
UPPERCASE_LETTER | OTHER_LETTER |
TITLECASE_LETTER | LETTER_NUMBER => true
case _ => ch == '_'
case _ => ":_".contains(ch)
}
}

Expand Down
3 changes: 1 addition & 2 deletions shared/src/test/scala/scala/xml/UtilityTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package scala.xml

import org.junit.Test
import org.junit.Assert.assertTrue
import org.junit.Assert.assertFalse
import org.junit.Assert.assertEquals

class UtilityTest {

@Test
def isNameStart: Unit = {
assertTrue(Utility.isNameStart('b'))
assertFalse(Utility.isNameStart(':'))
assertTrue(Utility.isNameStart(':'))
}

@Test
Expand Down