Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions shared/src/main/scala/scala/xml/Utility.scala
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ object Utility extends AnyRef with parsing.TokenTests {
val hex: Boolean = (ch() == 'x') && { nextch(); true }
val base: Int = if (hex) 16 else 10
var i: Int = 0
while (ch() != ';') {
while (ch() != ';' && ch() != 0) {
ch() match {
case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' =>
i = i * base + ch().asDigit
Expand All @@ -410,6 +410,6 @@ object Utility extends AnyRef with parsing.TokenTests {
}
nextch()
}
new String(Array(i), 0, 1)
if (i != 0) new String(Array(i), 0, 1) else ""
}
}
11 changes: 11 additions & 0 deletions shared/src/test/scala/scala/xml/UtilityTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,15 @@ class UtilityTest {
val x: Elem = <div>{Text(" My name ")}{Text(" is ")}{Text(" Harry ")}</div>
assertEquals(<div>My name is Harry</div>, Utility.trim(x))
}

@Test
def issue306InvalidUnclosedEntity(): Unit = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the name of the test method should be more specific: this is about character references, not entities in general...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing that. I have updated the test method to use CharRef instead. I also created ticket #656 for the other infinite loop issue.

val entity = "&# test </body></html>"
val it: Iterator[Char] = entity.iterator
var c = it.next()
val next = () => if (it.hasNext) c = it.next() else c = 0.asInstanceOf[Char]
val result = Utility.parseCharRef({ () => c }, next, _ => {}, _ => {})
assertEquals("", result)
}

}