Check for invalid tags.

This commit is contained in:
chriseth 2021-03-01 17:13:28 +01:00
parent 5690020d88
commit d2023f5f95
2 changed files with 32 additions and 1 deletions

View File

@ -27,9 +27,14 @@
#include <libsolidity/parsing/DocStringParser.h>
#include <libsolidity/analysis/NameAndTypeResolver.h>
#include <liblangutil/ErrorReporter.h>
#include <liblangutil/Common.h>
#include <range/v3/algorithm/any_of.hpp>
#include <boost/algorithm/string.hpp>
#include <regex>
using namespace std;
using namespace solidity;
using namespace solidity::langutil;
@ -157,8 +162,18 @@ void DocStringTagParser::parseDocStrings(
size_t returnTagsVisited = 0;
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;
}
else if (!_validTags.count(tagName))
m_errorReporter.docstringParsingError(
6546_error,

View 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.