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 * Add test_allocator to extras/test
* More flat_streambuf tests * More flat_streambuf tests
* WebSocket doc work * WebSocket doc work
* Prevent basic_fields operator[] assignment
API Changes: API Changes:

View File

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

View File

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

View File

@ -18,17 +18,17 @@ class basic_fields_test : public beast::unit_test::suite
{ {
public: public:
template<class Allocator> 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> template<class Allocator>
static static
void 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) 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> template<class U, class V>
@ -41,46 +41,46 @@ public:
void testHeaders() void testHeaders()
{ {
bh h1; f_t f1;
BEAST_EXPECT(h1.empty()); BEAST_EXPECT(f1.empty());
fill(1, h1); fill(1, f1);
BEAST_EXPECT(h1.size() == 1); BEAST_EXPECT(f1.size() == 1);
bh h2; f_t f2;
h2 = h1; f2 = f1;
BEAST_EXPECT(h2.size() == 1); BEAST_EXPECT(f2.size() == 1);
h2.insert("2", "2"); f2.insert("2", "2");
BEAST_EXPECT(std::distance(h2.begin(), h2.end()) == 2); BEAST_EXPECT(std::distance(f2.begin(), f2.end()) == 2);
h1 = std::move(h2); f1 = std::move(f2);
BEAST_EXPECT(h1.size() == 2); BEAST_EXPECT(f1.size() == 2);
BEAST_EXPECT(h2.size() == 0); BEAST_EXPECT(f2.size() == 0);
bh h3(std::move(h1)); f_t f3(std::move(f1));
BEAST_EXPECT(h3.size() == 2); BEAST_EXPECT(f3.size() == 2);
BEAST_EXPECT(h1.size() == 0); BEAST_EXPECT(f1.size() == 0);
self_assign(h3, std::move(h3)); self_assign(f3, std::move(f3));
BEAST_EXPECT(h3.size() == 2); BEAST_EXPECT(f3.size() == 2);
BEAST_EXPECT(h2.erase("Not-Present") == 0); BEAST_EXPECT(f2.erase("Not-Present") == 0);
} }
void testRFC2616() void testRFC2616()
{ {
bh h; f_t f;
h.insert("a", "w"); f.insert("a", "w");
h.insert("a", "x"); f.insert("a", "x");
h.insert("aa", "y"); f.insert("aa", "y");
h.insert("b", "z"); f.insert("b", "z");
BEAST_EXPECT(h.count("a") == 2); BEAST_EXPECT(f.count("a") == 2);
} }
void testErase() void testErase()
{ {
bh h; f_t f;
h.insert("a", "w"); f.insert("a", "w");
h.insert("a", "x"); f.insert("a", "x");
h.insert("aa", "y"); f.insert("aa", "y");
h.insert("b", "z"); f.insert("b", "z");
BEAST_EXPECT(h.size() == 4); BEAST_EXPECT(f.size() == 4);
h.erase("a"); f.erase("a");
BEAST_EXPECT(h.size() == 2); BEAST_EXPECT(f.size() == 2);
} }
void run() override void run() override

View File

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