Skip to content

Commit

Permalink
Resolved issue (#445) with empty query parameter values.
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-crowhurst committed Jul 1, 2021
1 parent ed83f45 commit 5817f08
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/corvusoft/restbed/uri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ namespace restbed
{
auto index = parameter.find_first_of( '=' );
auto name = decode_parameter( parameter.substr( 0, index ) );
auto value = decode_parameter( parameter.substr( index + 1, parameter.length( ) ) );
auto value = (index not_eq string::npos) ? decode_parameter( parameter.substr( index + 1, parameter.length( ) ) ) : "";

parameters.insert( make_pair( name, value ) );
}
Expand Down
4 changes: 4 additions & 0 deletions test/regression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,7 @@ add_test( request_returning_body_from_prior_requests_regression_test_suite ${EXE
add_executable( ssl_settings_to_handle_windows_path_regression_test_suite ${SOURCE_DIR}/ssl_settings_to_handle_windows_paths.cpp )
target_link_libraries( ssl_settings_to_handle_windows_path_regression_test_suite ${STATIC_LIBRARY_NAME} )
add_test( ssl_settings_to_handle_windows_path_regression_test_suite ${EXECUTABLE_OUTPUT_PATH}/ssl_settings_to_handle_windows_path_regression_test_suite )

add_executable( uri_get_parameter_fails_to_handle_empty_values_regression_test_suite ${SOURCE_DIR}/uri_get_parameter_fails_to_handle_empty_values.cpp )
target_link_libraries( uri_get_parameter_fails_to_handle_empty_values_regression_test_suite ${STATIC_LIBRARY_NAME} )
add_test( uri_get_parameter_fails_to_handle_empty_values_regression_test_suite ${EXECUTABLE_OUTPUT_PATH}/uri_get_parameter_fails_to_handle_empty_values_regression_test_suite )
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//System Includes
#include <map>
#include <string>

//Project Includes
#include <restbed>

//External Includes
#include <catch.hpp>

//System Namespaces
using std::string;
using std::multimap;

//Project Namespaces
using namespace restbed;

//External Namespaces

TEST_CASE( "uri get parameter fails to handle empty values", "[uri]" )
{
multimap< string, string > expectation {{"param", "1"}};
Uri uri_with_value( "http://www.corvusoft.co.uk?param=1" );
REQUIRE( uri_with_value.get_query_parameters( ) == expectation );

expectation = {{"param", ""}};
Uri uri_blank_param( "http://www.corvusoft.co.uk?param=" );
REQUIRE( uri_blank_param.get_query_parameters( ) == expectation );

Uri uri_empty_param( "http://www.corvusoft.co.uk?param" );
REQUIRE( uri_empty_param.get_query_parameters( ) == expectation );
}

0 comments on commit 5817f08

Please sign in to comment.