summaryrefslogtreecommitdiffstats
path: root/src/common/HTMLFormatter.cc
diff options
context:
space:
mode:
authorSage Weil <sage@redhat.com>2018-04-10 05:25:17 +0200
committerSage Weil <sage@redhat.com>2018-04-10 05:40:58 +0200
commit54f1e4e614dcd185d28c5644fc049a6ea2838d12 (patch)
tree8a2ea83c8267ccc6d8364df0882478fe1e230af7 /src/common/HTMLFormatter.cc
parentMerge pull request #21295 from badone/wip-large-omap-scrub-big-random-loser-2 (diff)
downloadceph-54f1e4e614dcd185d28c5644fc049a6ea2838d12.tar.xz
ceph-54f1e4e614dcd185d28c5644fc049a6ea2838d12.zip
common/Formatter: fix string_view usage for {json,xml}_stream_escaper
These are passing a simple const char* without a length, which breaks for binary strings with \0 in them. Broken by b40f76a7a0cf460f2a851b001885a4831a6f6503. This code is still a mess because there is a mix of boost::string_view and std::string_view throughout the code. A cleanup is in order! Signed-off-by: Sage Weil <sage@redhat.com>
Diffstat (limited to 'src/common/HTMLFormatter.cc')
-rw-r--r--src/common/HTMLFormatter.cc12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/common/HTMLFormatter.cc b/src/common/HTMLFormatter.cc
index 1ad6a6d88e5..725bc39ff70 100644
--- a/src/common/HTMLFormatter.cc
+++ b/src/common/HTMLFormatter.cc
@@ -114,7 +114,7 @@ void HTMLFormatter::dump_float(const char *name, double d)
void HTMLFormatter::dump_string(const char *name, std::string_view s)
{
- dump_template(name, xml_stream_escaper(s.data()));
+ dump_template(name, xml_stream_escaper(s));
}
void HTMLFormatter::dump_string_with_attrs(const char *name, std::string_view s, const FormatterAttrs& attrs)
@@ -123,7 +123,7 @@ void HTMLFormatter::dump_string_with_attrs(const char *name, std::string_view s,
std::string attrs_str;
get_attrs_str(&attrs, attrs_str);
print_spaces();
- m_ss << "<li>" << e << ": " << xml_stream_escaper(s.data()) << attrs_str << "</li>";
+ m_ss << "<li>" << e << ": " << xml_stream_escaper(s) << attrs_str << "</li>";
if (m_pretty)
m_ss << "\n";
}
@@ -139,14 +139,16 @@ std::ostream& HTMLFormatter::dump_stream(const char *name)
void HTMLFormatter::dump_format_va(const char* name, const char *ns, bool quoted, const char *fmt, va_list ap)
{
char buf[LARGE_SIZE];
- vsnprintf(buf, LARGE_SIZE, fmt, ap);
+ size_t len = vsnprintf(buf, LARGE_SIZE, fmt, ap);
std::string e(name);
print_spaces();
if (ns) {
- m_ss << "<li xmlns=\"" << ns << "\">" << e << ": " << xml_stream_escaper(buf) << "</li>";
+ m_ss << "<li xmlns=\"" << ns << "\">" << e << ": "
+ << xml_stream_escaper(std::string_view(buf, len)) << "</li>";
} else {
- m_ss << "<li>" << e << ": " << xml_stream_escaper(buf) << "</li>";
+ m_ss << "<li>" << e << ": "
+ << xml_stream_escaper(std::string_view(buf, len)) << "</li>";
}
if (m_pretty)