diff --git a/ksoup-html/src/commonMain/kotlin/com/mohamedrejeb/ksoup/html/tokenizer/KsoupTokenizer.kt b/ksoup-html/src/commonMain/kotlin/com/mohamedrejeb/ksoup/html/tokenizer/KsoupTokenizer.kt
index a9bf6b4..27ee32e 100644
--- a/ksoup-html/src/commonMain/kotlin/com/mohamedrejeb/ksoup/html/tokenizer/KsoupTokenizer.kt
+++ b/ksoup-html/src/commonMain/kotlin/com/mohamedrejeb/ksoup/html/tokenizer/KsoupTokenizer.kt
@@ -515,7 +515,7 @@ internal class KsoupTokenizer(
private fun stateInEntity(c: Int) {
if (c == CharCodes.Semi.code) {
val decoded = KsoupEntities.decodeHtml(
- this.buffer.substring(this.entityStart, this.index + 1)
+ this.buffer.substring(this.entityStart - this.offset, this.index - this.offset + 1)
)
this.state = this.baseState
@@ -874,4 +874,4 @@ internal class KsoupTokenizer(
}
}
-}
\ No newline at end of file
+}