mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Return UTF-8 error in BoolResult and remove it from string type
This commit is contained in:
parent
a154594de6
commit
e54110ff17
@ -1357,11 +1357,19 @@ BoolResult StringLiteralType::isImplicitlyConvertibleTo(Type const& _convertTo)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (auto arrayType = dynamic_cast<ArrayType const*>(&_convertTo))
|
else if (auto arrayType = dynamic_cast<ArrayType const*>(&_convertTo))
|
||||||
|
{
|
||||||
|
size_t invalidSequence;
|
||||||
|
if (arrayType->isString() && !util::validateUTF8(value(), invalidSequence))
|
||||||
|
return BoolResult::err(
|
||||||
|
"Contains invalid UTF-8 sequence at position " +
|
||||||
|
util::toString(invalidSequence) +
|
||||||
|
"."
|
||||||
|
);
|
||||||
return
|
return
|
||||||
arrayType->location() != DataLocation::CallData &&
|
arrayType->location() != DataLocation::CallData &&
|
||||||
arrayType->isByteArray() &&
|
arrayType->isByteArray() &&
|
||||||
!(arrayType->dataStoredIn(DataLocation::Storage) && arrayType->isPointer()) &&
|
!(arrayType->dataStoredIn(DataLocation::Storage) && arrayType->isPointer());
|
||||||
!(arrayType->isString() && !util::validateUTF8(value()));
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1392,15 +1400,9 @@ std::string StringLiteralType::toString(bool) const
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
string ret = isPrintableASCII(m_value) ?
|
return isPrintableASCII(m_value) ?
|
||||||
("literal_string \"" + m_value + "\"") :
|
("literal_string \"" + m_value + "\"") :
|
||||||
("literal_string hex\"" + util::toHex(util::asBytes(m_value)) + "\"");
|
("literal_string hex\"" + util::toHex(util::asBytes(m_value)) + "\"");
|
||||||
|
|
||||||
size_t invalidSequence;
|
|
||||||
if (!util::validateUTF8(m_value, invalidSequence))
|
|
||||||
ret += " (contains invalid UTF-8 sequence at position " + util::toString(invalidSequence) + ")";
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TypePointer StringLiteralType::mobileType() const
|
TypePointer StringLiteralType::mobileType() const
|
||||||
|
@ -86,7 +86,7 @@
|
|||||||
"typeDescriptions":
|
"typeDescriptions":
|
||||||
{
|
{
|
||||||
"typeIdentifier": "t_stringliteral_8b1a944cf13a9a1c08facb2c9e98623ef3254d2ddb48113885c3e8e97fec8db9",
|
"typeIdentifier": "t_stringliteral_8b1a944cf13a9a1c08facb2c9e98623ef3254d2ddb48113885c3e8e97fec8db9",
|
||||||
"typeString": "literal_string hex\"ff\" (contains invalid UTF-8 sequence at position 0)"
|
"typeString": "literal_string hex\"ff\""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nodeType": "VariableDeclarationStatement",
|
"nodeType": "VariableDeclarationStatement",
|
||||||
|
@ -131,7 +131,7 @@
|
|||||||
"isPure": true,
|
"isPure": true,
|
||||||
"lValueRequested": false,
|
"lValueRequested": false,
|
||||||
"token": "hexString",
|
"token": "hexString",
|
||||||
"type": "literal_string hex\"ff\" (contains invalid UTF-8 sequence at position 0)"
|
"type": "literal_string hex\"ff\""
|
||||||
},
|
},
|
||||||
"id": 5,
|
"id": 5,
|
||||||
"name": "Literal",
|
"name": "Literal",
|
||||||
|
@ -2,4 +2,4 @@ contract C {
|
|||||||
string s = string("\xa0\x00");
|
string s = string("\xa0\x00");
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// TypeError 9640: (28-46): Explicit type conversion not allowed from "literal_string hex"a000" (contains invalid UTF-8 sequence at position 0)" to "string memory".
|
// TypeError 9640: (28-46): Explicit type conversion not allowed from "literal_string hex"a000"" to "string memory". Contains invalid UTF-8 sequence at position 0.
|
||||||
|
@ -2,4 +2,4 @@ contract C {
|
|||||||
string s = hex"a000";
|
string s = hex"a000";
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// TypeError 7407: (28-37): Type literal_string hex"a000" (contains invalid UTF-8 sequence at position 0) is not implicitly convertible to expected type string storage ref.
|
// TypeError 7407: (28-37): Type literal_string hex"a000" is not implicitly convertible to expected type string storage ref. Contains invalid UTF-8 sequence at position 0.
|
||||||
|
@ -2,4 +2,4 @@ contract C {
|
|||||||
string s = "\xa0\x00";
|
string s = "\xa0\x00";
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// TypeError 7407: (28-38): Type literal_string hex"a000" (contains invalid UTF-8 sequence at position 0) is not implicitly convertible to expected type string storage ref.
|
// TypeError 7407: (28-38): Type literal_string hex"a000" is not implicitly convertible to expected type string storage ref. Contains invalid UTF-8 sequence at position 0.
|
||||||
|
@ -3,4 +3,4 @@ contract C {
|
|||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// SyntaxError 8452: (28-38): Contains invalid UTF-8 sequence at position 0.
|
// SyntaxError 8452: (28-38): Contains invalid UTF-8 sequence at position 0.
|
||||||
// TypeError 7407: (28-38): Type literal_string hex"c0" (contains invalid UTF-8 sequence at position 0) is not implicitly convertible to expected type string storage ref.
|
// TypeError 7407: (28-38): Type literal_string hex"c0" is not implicitly convertible to expected type string storage ref. Contains invalid UTF-8 sequence at position 0.
|
||||||
|
@ -4,4 +4,4 @@ contract test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// TypeError 6359: (86-92): Return argument type literal_string hex"c1" (contains invalid UTF-8 sequence at position 0) is not implicitly convertible to expected type (type of first return variable) string memory.
|
// TypeError 6359: (86-92): Return argument type literal_string hex"c1" is not implicitly convertible to expected type (type of first return variable) string memory. Contains invalid UTF-8 sequence at position 0.
|
||||||
|
@ -17,4 +17,4 @@ contract C {
|
|||||||
// TypeError 9640: (92-109): Explicit type conversion not allowed from "literal_string hex"1234"" to "bytes1". Literal is larger than the type.
|
// TypeError 9640: (92-109): Explicit type conversion not allowed from "literal_string hex"1234"" to "bytes1". Literal is larger than the type.
|
||||||
// TypeError 9640: (198-217): Explicit type conversion not allowed from "literal_string hex"123456"" to "bytes2". Literal is larger than the type.
|
// TypeError 9640: (198-217): Explicit type conversion not allowed from "literal_string hex"123456"" to "bytes2". Literal is larger than the type.
|
||||||
// TypeError 9640: (310-331): Explicit type conversion not allowed from "literal_string hex"12345678"" to "bytes3". Literal is larger than the type.
|
// TypeError 9640: (310-331): Explicit type conversion not allowed from "literal_string hex"12345678"" to "bytes3". Literal is larger than the type.
|
||||||
// TypeError 9640: (430-453): Explicit type conversion not allowed from "literal_string hex"1234567890" (contains invalid UTF-8 sequence at position 4)" to "bytes4". Literal is larger than the type.
|
// TypeError 9640: (430-453): Explicit type conversion not allowed from "literal_string hex"1234567890"" to "bytes4". Literal is larger than the type.
|
||||||
|
Loading…
Reference in New Issue
Block a user