Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/pcm-sensor-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2218,9 +2218,9 @@ class HTTPHeader {
while ( ss.good() ) {
std::getline( ss, s, listSeparatorChar );
// Remove leading whitespace
s.erase( s.begin(), std::find_if( s.begin(), s.end(), std::bind1st( std::not_equal_to<char>(), ' ' ) ) );
s.erase( s.begin(), std::find_if( s.begin(), s.end(), []( char c ){ return c != ' '; } ) );
// Remove trailing whitespace
s.erase( std::find_if( s.rbegin(), s.rend(), std::bind1st( std::not_equal_to<char>(), ' ') ).base(), s.end() );
s.erase( std::find_if( s.rbegin(), s.rend(), []( char c ){ return c != ' '; } ).base(), s.end() );
elementList.push_back( s );
}
return elementList;
Expand Down
6 changes: 3 additions & 3 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ fi

echo Testing urltest
./tests/urltest
# We have 12 expected errors, anything else is a bug
if [ "$?" != 12 ]; then
echo "Error in urltest, 12 expected errors but found $?!"
# We have 14 expected errors, anything else is a bug
if [ "$?" != 14 ]; then
echo "Error in urltest, 14 expected errors but found $?!"
exit 1
fi

Expand Down
22 changes: 20 additions & 2 deletions tests/urltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,19 @@ std::vector<std::string> urls{
"http://ww\x00\x00\x00rstmark\x0a"
};

std::vector<std::string> headers{
"Content-Encoding text/html", // Invalid header no colon found
" Content-Encoding : text/html ", // Valid header, should clean up the whitespace before and after
" H o s t : my.host.com", // Valid, spaces in header name should be accepted and silenty removed
"MyUnknownHeaderType : value", // Valid, MyUnknownHeaderType is considered a custom header type
" Host : \"my.host.com" // Invalid, header value not properly quoted
};

int main( int, char** ) {
int errors = 0;
// httpheader::debugPrint uses dbg(3), picking 5 for future changes
debug::dyn_debug_level( 5 );

int errors = 0, errors2 = 0;
for ( auto & s : urls ) {
try {
std::cout << s << "\n";
Expand All @@ -40,5 +51,12 @@ int main( int, char** ) {
++errors;
}
}
return errors;
for ( auto & h : headers ) {
std::cout << h << "\n";
HTTPHeader hh = HTTPHeader::parse( h );
hh.debugPrint();
if ( hh.type() == HeaderType::Invalid )
++errors2;
}
return errors+errors2;
}
Loading