container: root: common: PluggableSpace: add character checks/conversions

This commit is contained in:
2025-12-23 11:48:05 -08:00
parent 736a71e9d1
commit ce12412d10

View File

@@ -421,8 +421,52 @@ class PluggablePath
//! \since docker-finance 1.1.0
class PluggableSpace
{
public:
//! \brief Parses (or re-parses) constructed types
//! \warning Only call this function after constructing if underlying type::PluggableSpace has been changed (post-construction)
//! \return NPI reference
auto& parse()
{
auto const parser = [](const std::string& space) -> std::string {
std::string parsed{space};
// NOTE: allowed to be empty (for now)
if (!parsed.empty())
{
throw_ex_if<type::RuntimeError>(
!std::regex_match(
parsed,
std::regex{
"[a-zA-Z0-9:/_\\-]+"} /* TODO(unassigned): refine */),
"invalid characters in namespace");
if (parsed.find('/'))
{
parsed = std::regex_replace(parsed, std::regex{"/"}, "::");
}
if (parsed.find('-'))
{
parsed = std::regex_replace(parsed, std::regex{"-"}, "_");
}
}
return parsed;
};
m_space.outer(parser(m_space.outer()));
m_space.inner(parser(m_space.inner()));
return *this;
}
protected:
explicit PluggableSpace(const type::PluggableSpace& space) : m_space(space) {}
// \note Since the current presumption is that a PluggableSpace is likely
// to be derived from an operating system path (via PluggablePath),
// there's leeway for path-to-namespace conversions to be done here.
explicit PluggableSpace(const type::PluggableSpace& space) : m_space(space)
{
parse();
}
~PluggableSpace() = default;
PluggableSpace(const PluggableSpace&) = default;