=str Skip parsing when buffer size <= 0.
This commit is contained in:
parent
5fde3e6b99
commit
8bb19b39bf
2 changed files with 28 additions and 11 deletions
|
|
@ -545,6 +545,22 @@ class JsonFramingSpec extends PekkoSpec {
|
|||
probe.request(1).expectError() shouldBe a[PartialObjectException]
|
||||
}
|
||||
|
||||
"complete when completing inside an empty chars" in {
|
||||
val input = ByteString(" ")
|
||||
val probe = Source.single(input).via(JsonFraming.objectScanner(48)).runWith(TestSink.probe)
|
||||
|
||||
probe.ensureSubscription()
|
||||
probe.request(1).expectComplete()
|
||||
}
|
||||
|
||||
"complete when completing with an empty byte string" in {
|
||||
val input = ByteString()
|
||||
val probe = Source.single(input).via(JsonFraming.objectScanner(48)).runWith(TestSink.probe)
|
||||
|
||||
probe.ensureSubscription()
|
||||
probe.request(1).expectComplete()
|
||||
}
|
||||
|
||||
"fail when pushing and inside an object" in {
|
||||
val input = """ { "name": "john" }, { """
|
||||
Source
|
||||
|
|
|
|||
|
|
@ -115,20 +115,21 @@ import pekko.util.ByteString
|
|||
private def seekObject(): Boolean = {
|
||||
completedObject = false
|
||||
val bufSize = buffer.length
|
||||
if (bufSize > 0) {
|
||||
skipToNextObject(bufSize)
|
||||
val maxObjectLengthIndex = if (pos + maximumObjectLength < 0) Int.MaxValue else pos + maximumObjectLength
|
||||
|
||||
skipToNextObject(bufSize)
|
||||
val maxObjectLengthIndex = if (pos + maximumObjectLength < 0) Int.MaxValue else pos + maximumObjectLength
|
||||
while (pos < bufSize && pos < maxObjectLengthIndex && !completedObject) {
|
||||
val input = buffer(pos)
|
||||
proceed(input)
|
||||
pos += 1
|
||||
}
|
||||
|
||||
while (pos < bufSize && pos < maxObjectLengthIndex && !completedObject) {
|
||||
val input = buffer(pos)
|
||||
proceed(input)
|
||||
pos += 1
|
||||
}
|
||||
if (pos >= maxObjectLengthIndex)
|
||||
throw new FramingException(s"""JSON element exceeded maximumObjectLength ($maximumObjectLength bytes)!""")
|
||||
|
||||
if (pos >= maxObjectLengthIndex)
|
||||
throw new FramingException(s"""JSON element exceeded maximumObjectLength ($maximumObjectLength bytes)!""")
|
||||
|
||||
completedObject
|
||||
completedObject
|
||||
} else false
|
||||
}
|
||||
|
||||
private def skipToNextObject(bufSize: Int): Unit =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue