From 7ba967a36cead5cb79c6ef7911873cf5eae2775d Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 9 Jan 2020 15:54:52 +0100 Subject: [PATCH] Fix answer_type::get_header(). The previous implementation returned a reference to an out-of-scope string. --- include/answer.hpp | 4 +++- src/answer.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/answer.hpp b/include/answer.hpp index 56a8324..b0cafdf 100644 --- a/include/answer.hpp +++ b/include/answer.hpp @@ -103,7 +103,9 @@ struct answer_type /*! * @brief Returns the value of a header field. * - * Case insensitive, only ASCII. + * Is only valid for as long as the answer_type is in scope. + * + * @param field Case insensitive, only ASCII. * * @since 0.1.0 */ diff --git a/src/answer.cpp b/src/answer.cpp index 8cc9236..0db9176 100644 --- a/src/answer.cpp +++ b/src/answer.cpp @@ -54,7 +54,7 @@ string_view answer_type::get_header(const string_view field) const auto pos{static_cast(it - headers.begin())}; pos = headers.find(':', pos) + 2; const auto endpos{headers.find('\n', pos)}; - return headers.substr(pos, endpos - pos); + return string_view(&headers[pos], endpos - pos); } return {};