Skip to content

Commit

Permalink
Fix IndexOutOfBounds when parsing a wrong Html (#22)
Browse files Browse the repository at this point in the history
* Fix issue with encoding some html entities

* Fix issues with decoding emoji

* Fix IndexOutOfBounds when parsing a wrong Html
  • Loading branch information
MohamedRejeb authored Sep 1, 2023
1 parent 3f0ce25 commit 5d88c58
Show file tree
Hide file tree
Showing 3 changed files with 763 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public class KsoupHtmlParser(
this.endOpenTag(isOpenImplied)

// Self-closing tags will be on the top of the stack
if (this.stack[this.stack.size - 1] == name) {
if (this.stack.getOrNull(this.stack.size - 1) == name) {
// If the opening tag isn't implied, the closing tag has to be implied.
this.handler.onCloseTag(name, !isOpenImplied)
this.stack.removeLast()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,17 @@ class KsoupHtmlParserTest {
expectedString = "First lineSecond line",
)
}

@Test
fun testBigHtml() {
val handler = KsoupHtmlHandler
.Builder()
.build()

val ksoupHtmlParser = KsoupHtmlParser(
handler = handler,
)
ksoupHtmlParser.write(TestData.htmlString)
ksoupHtmlParser.end()
}
}
Loading

0 comments on commit 5d88c58

Please # to comment.