change regex
This commit is contained in:
parent
7cb45243fe
commit
3fb8af512c
|
@ -107,6 +107,7 @@ class MerkleBlockTest(BitcoinTestFramework):
|
||||||
assert_equal(self.nodes[0].getblock("-107")["height"], 1)
|
assert_equal(self.nodes[0].getblock("-107")["height"], 1)
|
||||||
assert_equal(self.nodes[0].getblock("-108")["height"], 0)
|
assert_equal(self.nodes[0].getblock("-108")["height"], 0)
|
||||||
assert_raises(JSONRPCException, self.nodes[0].getblock, ["-109"])
|
assert_raises(JSONRPCException, self.nodes[0].getblock, ["-109"])
|
||||||
|
assert_raises(JSONRPCException, self.nodes[0].getblock, ["-0"])
|
||||||
|
|
||||||
# Test getblockhash negative heights
|
# Test getblockhash negative heights
|
||||||
assert_equal(self.nodes[0].getblockhash(-1), self.nodes[0].getblockhash(107))
|
assert_equal(self.nodes[0].getblockhash(-1), self.nodes[0].getblockhash(107))
|
||||||
|
|
|
@ -588,7 +588,7 @@ UniValue getblockhash(const UniValue& params, bool fHelp)
|
||||||
|
|
||||||
int nHeight = params[0].get_int();
|
int nHeight = params[0].get_int();
|
||||||
|
|
||||||
if(nHeight < 0) {
|
if (nHeight < 0) {
|
||||||
nHeight += chainActive.Height() + 1;
|
nHeight += chainActive.Height() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -711,7 +711,7 @@ UniValue getblock(const UniValue& params, bool fHelp)
|
||||||
// If height is supplied, find the hash
|
// If height is supplied, find the hash
|
||||||
if (strHash.size() < (2 * sizeof(uint256))) {
|
if (strHash.size() < (2 * sizeof(uint256))) {
|
||||||
// std::stoi allows characters, whereas we want to be strict
|
// std::stoi allows characters, whereas we want to be strict
|
||||||
regex r("-?[[:digit:]]+");
|
regex r("(?:(-?)[1-9][0-9]*|[0-9]+)");
|
||||||
if (!regex_match(strHash, r)) {
|
if (!regex_match(strHash, r)) {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block height parameter");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block height parameter");
|
||||||
}
|
}
|
||||||
|
@ -724,7 +724,7 @@ UniValue getblock(const UniValue& params, bool fHelp)
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block height parameter");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block height parameter");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nHeight < 0) {
|
if (nHeight < 0) {
|
||||||
nHeight += chainActive.Height() + 1;
|
nHeight += chainActive.Height() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue