mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Check for invalid tags.
This commit is contained in:
parent
5690020d88
commit
d2023f5f95
@ -27,9 +27,14 @@
|
|||||||
#include <libsolidity/parsing/DocStringParser.h>
|
#include <libsolidity/parsing/DocStringParser.h>
|
||||||
#include <libsolidity/analysis/NameAndTypeResolver.h>
|
#include <libsolidity/analysis/NameAndTypeResolver.h>
|
||||||
#include <liblangutil/ErrorReporter.h>
|
#include <liblangutil/ErrorReporter.h>
|
||||||
|
#include <liblangutil/Common.h>
|
||||||
|
|
||||||
|
#include <range/v3/algorithm/any_of.hpp>
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::langutil;
|
using namespace solidity::langutil;
|
||||||
@ -157,8 +162,18 @@ void DocStringTagParser::parseDocStrings(
|
|||||||
size_t returnTagsVisited = 0;
|
size_t returnTagsVisited = 0;
|
||||||
for (auto const& [tagName, tagValue]: _annotation.docTags)
|
for (auto const& [tagName, tagValue]: _annotation.docTags)
|
||||||
{
|
{
|
||||||
if (boost::starts_with(tagName, "custom:") && tagName.size() > string("custom:").size())
|
string static const customPrefix("custom:");
|
||||||
|
if (boost::starts_with(tagName, customPrefix) && tagName.size() > customPrefix.size())
|
||||||
|
{
|
||||||
|
regex static const customRegex("^custom:[a-z][a-z-]*$");
|
||||||
|
if (!regex_match(tagName, customRegex))
|
||||||
|
m_errorReporter.docstringParsingError(
|
||||||
|
2968_error,
|
||||||
|
_node.documentation()->location(),
|
||||||
|
"Invalid character in custom tag @" + tagName + ". Only lowercase letters and \"-\" are permitted."
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
else if (!_validTags.count(tagName))
|
else if (!_validTags.count(tagName))
|
||||||
m_errorReporter.docstringParsingError(
|
m_errorReporter.docstringParsingError(
|
||||||
6546_error,
|
6546_error,
|
||||||
|
16
test/libsolidity/syntaxTests/natspec/invalid/invalid_tag.sol
Normal file
16
test/libsolidity/syntaxTests/natspec/invalid/invalid_tag.sol
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/// @a&b test
|
||||||
|
contract C {
|
||||||
|
/// @custom:x^y test2
|
||||||
|
function f() public pure {}
|
||||||
|
/// @custom:
|
||||||
|
function g() public pure {}
|
||||||
|
/// @custom:abcDEF
|
||||||
|
function h() public pure {}
|
||||||
|
/// @custom:abc-def
|
||||||
|
function i() public pure {}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// DocstringParsingError 6546: (0-14): Documentation tag @a&b not valid for contracts.
|
||||||
|
// DocstringParsingError 2968: (28-49): Invalid character in custom tag @custom:x^y. Only lowercase letters and "-" are permitted.
|
||||||
|
// DocstringParsingError 6546: (80-92): Documentation tag @custom: not valid for functions.
|
||||||
|
// DocstringParsingError 2968: (123-141): Invalid character in custom tag @custom:abcDEF. Only lowercase letters and "-" are permitted.
|
Loading…
Reference in New Issue
Block a user