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
2 changes: 2 additions & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Changelog {#Changelog}

# git master {#master}
* [43](https://github.com/HBPVis/Servus/pull/43):
Allow URI queries without value

# Release 1.3 (07-03-2015)

Expand Down
2 changes: 1 addition & 1 deletion servus/serializable.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Serializable
*/
bool fromJSON( const std::string& json ) { return _fromJSON( json ); }

/** @return the JSON representation of this object. */
/** @return the JSON representation of this serializable. */
std::string toJSON() const { return _toJSON(); }
//@}

Expand Down
11 changes: 7 additions & 4 deletions servus/uri.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright (c) 2013-2015, Human Brain Project
/* Copyright (c) 2013-2016, Human Brain Project
* Ahmet.Bilgili@epfl.ch
* 2015, Juan Hernando <jhernando@fi.upm.es>
* Juan Hernando <jhernando@fi.upm.es>
*
* This file is part of Servus <https://github.com/HBPVIS/Servus>
*
Expand Down Expand Up @@ -167,9 +167,12 @@ void _parseQueryMap( URIData& data )
query = query.substr( nextPair + 1 );

const size_t eq = pair.find( '=' );
if( eq == std::string::npos || eq == 0 )
if( eq == 0 ) // empty key
continue;
data.queryMap[ pair.substr( 0, eq ) ] = pair.substr( eq + 1 );
if( eq == std::string::npos ) // empty value
data.queryMap[ pair ] = std::string();
else
data.queryMap[ pair.substr( 0, eq ) ] = pair.substr( eq + 1 );
}
}

Expand Down
34 changes: 22 additions & 12 deletions tests/uri.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (c) 2013-2014, ahmet.bilgili@epfl.ch
* 2015, Juan Hernando <jhernando@fi.upm.es>
/* Copyright (c) 2013-2016, Ahmet.Bilgili@epfl.ch
* Juan Hernando <jhernando@fi.upm.es>
*
* This file is part of Servus <https://github.com/HBPVIS/Servus>
*
Expand All @@ -23,7 +23,7 @@
#include <servus/uri.h>


BOOST_AUTO_TEST_CASE(test_uri_parts)
BOOST_AUTO_TEST_CASE(uri_parts)
{
const std::string uriStr =
"http://bob@www.example.com:8080/path/?key=value,foo=bar#fragment";
Expand Down Expand Up @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(test_uri_parts)
BOOST_CHECK_EQUAL( fragment.getFragment(), "fragment,no,query" );
}

BOOST_AUTO_TEST_CASE(test_setters)
BOOST_AUTO_TEST_CASE(setters)
{
servus::URI uri;
uri.setScheme( "foo" );
Expand All @@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE(test_setters)
// The query setter is tested independently.
}

BOOST_AUTO_TEST_CASE(test_empty_uri)
BOOST_AUTO_TEST_CASE(empty_uri)
{
servus::URI empty;
BOOST_CHECK( empty.getScheme().empty( ));
Expand All @@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(test_empty_uri)
BOOST_CHECK( empty.getFragment().empty( ));
}

BOOST_AUTO_TEST_CASE(test_file_uris)
BOOST_AUTO_TEST_CASE(file_uris)
{
servus::URI file1( "/bla.txt" );
BOOST_CHECK_EQUAL( file1.getPath(), "/bla.txt" );
Expand Down Expand Up @@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE(test_file_uris)
BOOST_CHECK( file5.getFragment().empty( ));
}

BOOST_AUTO_TEST_CASE(test_uri_query)
BOOST_AUTO_TEST_CASE(uri_query)
{
const std::string uriStr =
"http://bob@www.example.com:8080/path/?key=value,foo=bar#fragment";
Expand All @@ -166,7 +166,7 @@ BOOST_AUTO_TEST_CASE(test_uri_query)
BOOST_CHECK( uri.getQuery().find( "hans=dampf" ) != std::string::npos );
}

BOOST_AUTO_TEST_CASE(test_uri_comparisons)
BOOST_AUTO_TEST_CASE(uri_comparisons)
{
const std::string uriStr =
"http://bob@www.example.com:8080/path/?key=value,foo=bar#fragment";
Expand Down Expand Up @@ -194,7 +194,7 @@ BOOST_AUTO_TEST_CASE(test_uri_comparisons)
BOOST_CHECK_EQUAL( sstr.str(), "/path" );
}

BOOST_AUTO_TEST_CASE(test_invalid_uri)
BOOST_AUTO_TEST_CASE(invalid_uri)
{
BOOST_CHECK_THROW( servus::URI uri( "bad_schema://" ),
std::exception );
Expand All @@ -209,7 +209,7 @@ BOOST_AUTO_TEST_CASE(test_invalid_uri)
std::exception );
}

BOOST_AUTO_TEST_CASE(test_corner_cases)
BOOST_AUTO_TEST_CASE(corner_cases)
{
servus::URI uri1( "path/foo:bar" );
BOOST_CHECK_EQUAL( uri1.getPath(), "path/foo:bar" );
Expand All @@ -228,7 +228,7 @@ BOOST_AUTO_TEST_CASE(test_corner_cases)
BOOST_CHECK_EQUAL( uri6.getHost(), "*" );
}

BOOST_AUTO_TEST_CASE(test_print)
BOOST_AUTO_TEST_CASE(print)
{
servus::URI uri;
BOOST_CHECK_EQUAL( std::to_string( uri ), "" );
Expand Down Expand Up @@ -269,7 +269,7 @@ BOOST_AUTO_TEST_CASE(test_print)
"foo://user@localhost:1024/path?key=value#fragment" );
}

BOOST_AUTO_TEST_CASE(test_host_port_without_schema)
BOOST_AUTO_TEST_CASE(host_port_without_schema)
{
const servus::URI uri( "host:12345" );
BOOST_CHECK_EQUAL( uri.getHost(), "" );
Expand All @@ -288,3 +288,13 @@ BOOST_AUTO_TEST_CASE(test_host_port_without_schema)
BOOST_CHECK_EQUAL( uri3.getHost(), "host" );
BOOST_CHECK_EQUAL( uri3.getPort(), 12345 );
}

BOOST_AUTO_TEST_CASE(query_without_value)
{
const servus::URI uri( "?foo=,bar=foo,blubb" );
BOOST_CHECK( uri.findQuery( "foo" ) != uri.queryEnd( ));
BOOST_CHECK( uri.findQuery( "blubb" ) != uri.queryEnd( ));
BOOST_CHECK_EQUAL( uri.findQuery( "bar" )->second, "foo" );
BOOST_CHECK( uri.findQuery( "foo" )->second.empty( ));
BOOST_CHECK( uri.findQuery( "blubb" )->second.empty( ));
}