problem: in some cases WS may produce empty or broken messages that breaks the connection
solution: better handling for invalid JSON (cherry picked from commit 1b6a995c4e746f0704643426fc20f7496fc09cef)
This commit is contained in:
@@ -223,4 +223,27 @@ class ResponseRpcParserSpec extends Specification {
|
||||
!act.hasResult()
|
||||
}
|
||||
|
||||
def "Keep provided ID even if JSON is not full"() {
|
||||
setup:
|
||||
def json = '{"jsonrpc": "2.0", "id": 1}'
|
||||
when:
|
||||
def act = parser.parse(json.getBytes())
|
||||
then:
|
||||
act.id.asNumber() == 1
|
||||
act.error != null
|
||||
act.hasError()
|
||||
!act.hasResult()
|
||||
}
|
||||
|
||||
def "Keep provided ID even if JSON is broken"() {
|
||||
setup:
|
||||
def json = '{"jsonrpc": "2.0", "id": 101, "resu'
|
||||
when:
|
||||
def act = parser.parse(json.getBytes())
|
||||
then:
|
||||
act.id.asNumber() == 101
|
||||
act.error != null
|
||||
act.hasError()
|
||||
!act.hasResult()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,4 +103,24 @@ class ResponseWSParserSpec extends Specification {
|
||||
act.error == null
|
||||
new String(act.value) == "null"
|
||||
}
|
||||
|
||||
def "Keep provided ID even if JSON is not full"() {
|
||||
setup:
|
||||
def json = '{"jsonrpc": "2.0", "id": 1}'
|
||||
when:
|
||||
def act = parser.parse(json.getBytes())
|
||||
then:
|
||||
act.id.asNumber() == 1
|
||||
act.error != null
|
||||
}
|
||||
|
||||
def "Keep provided ID even if JSON is broken"() {
|
||||
setup:
|
||||
def json = '{"jsonrpc": "2.0", "id": 101, "resu'
|
||||
when:
|
||||
def act = parser.parse(json.getBytes())
|
||||
then:
|
||||
act.id.asNumber() == 101
|
||||
act.error != null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user