Prevent basic_fields operator[] assignment

fix #258
This commit is contained in:
Vinnie Falco
2017-05-02 12:03:34 -07:00
parent f7a0885d17
commit 1a1a1d508b
5 changed files with 41 additions and 40 deletions

View File

@ -7,6 +7,7 @@
* Add test_allocator to extras/test
* More flat_streambuf tests
* WebSocket doc work
* Prevent basic_fields operator[] assignment
API Changes:

View File

@ -216,7 +216,7 @@ public:
If more than one field with the specified name exists, the
first field defined by insertion order is returned.
*/
boost::string_ref
boost::string_ref const
operator[](boost::string_ref const& name) const;
/// Clear the contents of the basic_fields.

View File

@ -192,7 +192,7 @@ find(boost::string_ref const& name) const ->
}
template<class Allocator>
boost::string_ref
boost::string_ref const
basic_fields<Allocator>::
operator[](boost::string_ref const& name) const
{

View File

@ -18,17 +18,17 @@ class basic_fields_test : public beast::unit_test::suite
{
public:
template<class Allocator>
using bha = basic_fields<Allocator>;
using fa_t = basic_fields<Allocator>;
using bh = basic_fields<std::allocator<char>>;
using f_t = fa_t<std::allocator<char>>;
template<class Allocator>
static
void
fill(std::size_t n, basic_fields<Allocator>& h)
fill(std::size_t n, basic_fields<Allocator>& f)
{
for(std::size_t i = 1; i<= n; ++i)
h.insert(boost::lexical_cast<std::string>(i), i);
f.insert(boost::lexical_cast<std::string>(i), i);
}
template<class U, class V>
@ -41,46 +41,46 @@ public:
void testHeaders()
{
bh h1;
BEAST_EXPECT(h1.empty());
fill(1, h1);
BEAST_EXPECT(h1.size() == 1);
bh h2;
h2 = h1;
BEAST_EXPECT(h2.size() == 1);
h2.insert("2", "2");
BEAST_EXPECT(std::distance(h2.begin(), h2.end()) == 2);
h1 = std::move(h2);
BEAST_EXPECT(h1.size() == 2);
BEAST_EXPECT(h2.size() == 0);
bh h3(std::move(h1));
BEAST_EXPECT(h3.size() == 2);
BEAST_EXPECT(h1.size() == 0);
self_assign(h3, std::move(h3));
BEAST_EXPECT(h3.size() == 2);
BEAST_EXPECT(h2.erase("Not-Present") == 0);
f_t f1;
BEAST_EXPECT(f1.empty());
fill(1, f1);
BEAST_EXPECT(f1.size() == 1);
f_t f2;
f2 = f1;
BEAST_EXPECT(f2.size() == 1);
f2.insert("2", "2");
BEAST_EXPECT(std::distance(f2.begin(), f2.end()) == 2);
f1 = std::move(f2);
BEAST_EXPECT(f1.size() == 2);
BEAST_EXPECT(f2.size() == 0);
f_t f3(std::move(f1));
BEAST_EXPECT(f3.size() == 2);
BEAST_EXPECT(f1.size() == 0);
self_assign(f3, std::move(f3));
BEAST_EXPECT(f3.size() == 2);
BEAST_EXPECT(f2.erase("Not-Present") == 0);
}
void testRFC2616()
{
bh h;
h.insert("a", "w");
h.insert("a", "x");
h.insert("aa", "y");
h.insert("b", "z");
BEAST_EXPECT(h.count("a") == 2);
f_t f;
f.insert("a", "w");
f.insert("a", "x");
f.insert("aa", "y");
f.insert("b", "z");
BEAST_EXPECT(f.count("a") == 2);
}
void testErase()
{
bh h;
h.insert("a", "w");
h.insert("a", "x");
h.insert("aa", "y");
h.insert("b", "z");
BEAST_EXPECT(h.size() == 4);
h.erase("a");
BEAST_EXPECT(h.size() == 2);
f_t f;
f.insert("a", "w");
f.insert("a", "x");
f.insert("aa", "y");
f.insert("b", "z");
BEAST_EXPECT(f.size() == 4);
f.erase("a");
BEAST_EXPECT(f.size() == 2);
}
void run() override

View File

@ -634,7 +634,7 @@ public:
m.method = "GET";
m.version = 11;
m.url = "/";
m.fields["Content-Length"] = "5";
m.fields.insert("Content-Length", 5);
m.body = "*****";
async_write(os, m, handler{});
BEAST_EXPECT(handler::count() > 0);
@ -656,7 +656,7 @@ public:
m.method = "GET";
m.version = 11;
m.url = "/";
m.fields["Content-Length"] = "5";
m.fields.insert("Content-Length", 5);
m.body = "*****";
async_write(is, m, handler{});
BEAST_EXPECT(handler::count() > 0);