fixes `validateFixedLenHex` in graphql/ethapi.nim

now it can detect too long hex besides padding too short hex
This commit is contained in:
jangko 2021-05-12 08:12:26 +07:00
parent 86939d9248
commit 2d3d450075
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 14 additions and 0 deletions

View File

@ -350,6 +350,9 @@ proc validateFixedLenHex(x: Node, minLen: int, kind: string, padding = false): N
[kind, $expectedLen, $x.stringVal.len])
else:
padBytes(x, prefixLen, minLen * 2)
elif x.stringVal.len > expectedLen:
return err("$1 len is too long: expect $2 got $3" %
[kind, $expectedLen, $x.stringVal.len])
for i in prefixLen..<x.stringVal.len:
if x.stringVal[i] notin HexDigits:

View File

@ -521,3 +521,14 @@ mutation {
"""
errors = ["[2, 1]: Fatal: Instrument Error: query complexity exceed max(200), got 204: @[]"]
result = """null"""
[[units]]
name = "hex address is too long"
errors = ["[2, 11]: Error: 'address' got '\"0x095e7baea6a6c7c4c2dfeb977efac326af552d8700\"': Address len is too long: expect 42 got 44"]
code = """
{
account(address: "0x095e7baea6a6c7c4c2dfeb977efac326af552d8700") {
balance
}
}
"""