mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Updated Whiskers for checking invalid tags
For Example, raise an error if it contains invalid tags like <?ba<!b</b
This commit is contained in:
parent
1c77d30cea
commit
bfd83c966a
@ -34,6 +34,7 @@ using namespace solidity::util;
|
|||||||
Whiskers::Whiskers(string _template):
|
Whiskers::Whiskers(string _template):
|
||||||
m_template(std::move(_template))
|
m_template(std::move(_template))
|
||||||
{
|
{
|
||||||
|
checkTemplateValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
Whiskers& Whiskers::operator()(string _parameter, string _value)
|
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);
|
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
|
void Whiskers::checkParameterValid(string const& _parameter) const
|
||||||
{
|
{
|
||||||
static regex validParam("^" + paramRegex() + "$");
|
static regex validParam("^" + paramRegex() + "$");
|
||||||
|
@ -92,6 +92,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
// Prevent implicit cast to bool
|
// Prevent implicit cast to bool
|
||||||
Whiskers& operator()(std::string _parameter, long long);
|
Whiskers& operator()(std::string _parameter, long long);
|
||||||
|
void checkTemplateValid() const;
|
||||||
void checkParameterValid(std::string const& _parameter) const;
|
void checkParameterValid(std::string const& _parameter) const;
|
||||||
void checkParameterUnknown(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)
|
BOOST_AUTO_TEST_CASE(broken_conditional_with_else)
|
||||||
{
|
{
|
||||||
string templ = "<?b>X<!bY</b>";
|
string templ = "<?b>X<!bY</b>";
|
||||||
BOOST_CHECK_EQUAL(Whiskers(templ)("b", true).render(), "X<!bY");
|
BOOST_CHECK_THROW(Whiskers{templ}, WhiskersError);
|
||||||
BOOST_CHECK_EQUAL(Whiskers(templ)("b", false).render(), "");
|
|
||||||
|
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)
|
BOOST_AUTO_TEST_CASE(conditional_plus_params)
|
||||||
|
Loading…
Reference in New Issue
Block a user