Prevent the user from naming an object with "::" #91
This commit is contained in:
@@ -53,9 +53,31 @@ namespace chaiscript
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_word;
|
std::string m_word;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception thrown in the case that an object name is invalid because it contains illegal characters
|
||||||
|
*/
|
||||||
|
class illegal_name_error : public std::runtime_error
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
illegal_name_error(const std::string &t_name) throw()
|
||||||
|
: std::runtime_error("Reserved name not allowed in object name: " + t_name), m_name(t_name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~illegal_name_error() throw() {}
|
||||||
|
|
||||||
|
std::string name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception thrown in the case that an object name is invalid because it already exists in current context
|
* Exception thrown in the case that an object name is invalid because it already exists in current context
|
||||||
*/
|
*/
|
||||||
@@ -1115,6 +1137,10 @@ namespace chaiscript
|
|||||||
*/
|
*/
|
||||||
void validate_object_name(const std::string &name) const
|
void validate_object_name(const std::string &name) const
|
||||||
{
|
{
|
||||||
|
if (name.find("::") != std::string::npos) {
|
||||||
|
throw exception::illegal_name_error(name);
|
||||||
|
}
|
||||||
|
|
||||||
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
||||||
|
|
||||||
if (m_state.m_reserved_words.find(name) != m_state.m_reserved_words.end())
|
if (m_state.m_reserved_words.find(name) != m_state.m_reserved_words.end())
|
||||||
|
Reference in New Issue
Block a user