From 02f2da00a3c47415324643d60a0927f1907d0f9c Mon Sep 17 00:00:00 2001 From: "zhangzhiliang@caict.ac.cn" <52365304+zzl-caict@users.noreply.github.com> Date: Mon, 1 Jul 2019 11:29:45 +0800 Subject: [PATCH] Update uri.cpp fix #384 bug add url_encode method --- source/corvusoft/restbed/uri.cpp | 36 +++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/source/corvusoft/restbed/uri.cpp b/source/corvusoft/restbed/uri.cpp index 94cd923f..cc1e1186 100644 --- a/source/corvusoft/restbed/uri.cpp +++ b/source/corvusoft/restbed/uri.cpp @@ -93,6 +93,31 @@ namespace restbed return Uri( value ); } + string Uri::url_encode(const string& input) + { + string output = String::empty; + string hex = "0123456789abcdef"; + for(string::size_type i=0;i> 4]); + output.push_back(hex[input[i] & 0x0f]); + + } + + } + return output; // Better free() this up after use. + + } + string Uri::decode( const Bytes& value ) { return decode( string( value.begin( ), value.end( ) ) ); @@ -102,20 +127,21 @@ namespace restbed { string result = String::empty; - for ( string::size_type index = 0; index not_eq value.length( ); index++ ) + string valuedecode = url_encode(value); + for ( string::size_type index = 0; index not_eq valuedecode.length( ); index++ ) { - if ( value[ index ] == '%' ) + if ( valuedecode[ index ] == '%' ) { char hexidecimal[ 3 ] = { 0 }; - hexidecimal[ 0 ] = value[ ++index ]; - hexidecimal[ 1 ] = value[ ++index ]; + hexidecimal[ 0 ] = valuedecode[ ++index ]; + hexidecimal[ 1 ] = valuedecode[ ++index ]; char byte = static_cast< char >( strtol( hexidecimal, nullptr, 16 ) ); result.push_back( byte ); } else { - result.push_back( value[ index ] ); + result.push_back( valuedecode[ index ] ); } }