From d0ef714179372ac2022f95fe004f3af3fc36a548 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 3 Mar 2018 04:05:43 -0800 Subject: [PATCH] ircd::m::id: Tighten exception spec on boolean validators; tweak test grammar. --- include/ircd/m/id.h | 6 +++--- ircd/m/id.cc | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/ircd/m/id.h b/include/ircd/m/id.h index 91f2f3bf4..f001b01ac 100644 --- a/include/ircd/m/id.h +++ b/include/ircd/m/id.h @@ -19,8 +19,8 @@ namespace ircd::m IRCD_M_EXCEPTION(INVALID_MXID, BAD_SIGIL, http::BAD_REQUEST) bool my(const id &); - bool is_sigil(const char &c); - bool has_sigil(const string_view &); + bool is_sigil(const char &c) noexcept; + bool has_sigil(const string_view &) noexcept; } /// (Appendix 4.2) Common Identifier Format @@ -206,7 +206,7 @@ namespace ircd::m // Checks bool valid(const id::sigil &, const string_view &) noexcept; - bool valid_local(const id::sigil &, const string_view &); // Local part is valid + bool valid_local(const id::sigil &, const string_view &) noexcept; // Local part is valid bool valid_local_only(const id::sigil &, const string_view &) noexcept; // No :host void validate(const id::sigil &, const string_view &); // valid() | throws } diff --git a/ircd/m/id.cc b/ircd/m/id.cc index 86082d2e6..1035923b5 100644 --- a/ircd/m/id.cc +++ b/ircd/m/id.cc @@ -558,11 +558,12 @@ noexcept try { static const auto test { - &lit(char(sigil)) > &m::id::parser.prefix > &eoi + m::id::parser.prefix }; const char *start{begin(id)}; - return qi::parse(start, end(id), test); + const char *const stop{end(id)}; + return id.at(0) == sigil && qi::parse(start, stop, test) && start == stop; } catch(...) { @@ -572,29 +573,36 @@ catch(...) bool ircd::m::valid_local(const id::sigil &sigil, const string_view &id) +noexcept try { static const auto test { - &lit(char(sigil)) > m::id::parser.prefix + m::id::parser.prefix }; - const char *start{id.data()}; - return qi::parse(start, end(id), test); + const char *start{begin(id)}; + const char *const stop{end(id)}; + return id.at(0) == sigil && qi::parse(start, stop, test); +} +catch(...) +{ + return false; } bool ircd::m::has_sigil(const string_view &s) -try +noexcept try { return is_sigil(s.at(0)); } -catch(const std::out_of_range &e) +catch(...) { return false; } bool ircd::m::is_sigil(const char &c) +noexcept { const char *start{&c}; const char *const stop{start + 1};