mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #13560 from rajgaur98/develop
Updated Whiskers for checking invalid tags
This commit is contained in:
commit
70b0fb6366
@ -34,6 +34,7 @@ using namespace solidity::util;
|
||||
Whiskers::Whiskers(string _template):
|
||||
m_template(std::move(_template))
|
||||
{
|
||||
checkTemplateValid();
|
||||
}
|
||||
|
||||
Whiskers& Whiskers::operator()(string _parameter, string _value)
|
||||
@ -74,6 +75,17 @@ string Whiskers::render() const
|
||||
return replace(m_template, m_parameters, m_conditions, m_listParameters);
|
||||
}
|
||||
|
||||
void Whiskers::checkTemplateValid() const
|
||||
{
|
||||
regex validTemplate("<[#?!\\/]\\+{0,1}[a-zA-Z0-9_$-]+(?:[^a-zA-Z0-9_$>-]|$)");
|
||||
smatch match;
|
||||
assertThrow(
|
||||
!regex_search(m_template, match, validTemplate),
|
||||
WhiskersError,
|
||||
"Template contains an invalid/unclosed tag " + match.str()
|
||||
);
|
||||
}
|
||||
|
||||
void Whiskers::checkParameterValid(string const& _parameter) const
|
||||
{
|
||||
static regex validParam("^" + paramRegex() + "$");
|
||||
|
@ -92,6 +92,7 @@ public:
|
||||
private:
|
||||
// Prevent implicit cast to bool
|
||||
Whiskers& operator()(std::string _parameter, long long);
|
||||
void checkTemplateValid() const;
|
||||
void checkParameterValid(std::string const& _parameter) const;
|
||||
void checkParameterUnknown(std::string const& _parameter) const;
|
||||
|
||||
|
@ -88,8 +88,34 @@ BOOST_AUTO_TEST_CASE(conditional_with_else)
|
||||
BOOST_AUTO_TEST_CASE(broken_conditional_with_else)
|
||||
{
|
||||
string templ = "<?b>X<!bY</b>";
|
||||
BOOST_CHECK_EQUAL(Whiskers(templ)("b", true).render(), "X<!bY");
|
||||
BOOST_CHECK_EQUAL(Whiskers(templ)("b", false).render(), "");
|
||||
BOOST_CHECK_THROW(Whiskers{templ}, WhiskersError);
|
||||
|
||||
templ = "<?bX<!b>Y</b>";
|
||||
BOOST_CHECK_THROW(Whiskers{templ}, WhiskersError);
|
||||
|
||||
templ = "<?b>X<!b>Y</b";
|
||||
BOOST_CHECK_THROW(Whiskers{templ}, WhiskersError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(broken_conditional_value_with_else)
|
||||
{
|
||||
string templ = "<?+b>X<!+bY</+b>";
|
||||
BOOST_CHECK_THROW(Whiskers{templ}, WhiskersError);
|
||||
|
||||
templ = "<?+bX<!+b>Y</+b>";
|
||||
BOOST_CHECK_THROW(Whiskers{templ}, WhiskersError);
|
||||
|
||||
templ = "<?+b>X<!+b>Y</+b";
|
||||
BOOST_CHECK_THROW(Whiskers{templ}, WhiskersError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(broken_list_parameter)
|
||||
{
|
||||
string templ = "<#b><a></b";
|
||||
BOOST_CHECK_THROW(Whiskers{templ}, WhiskersError);
|
||||
|
||||
templ = "<#b<a></b>";
|
||||
BOOST_CHECK_THROW(Whiskers{templ}, WhiskersError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(conditional_plus_params)
|
||||
|
Loading…
Reference in New Issue
Block a user