name: don't strip whitespace when parsing URI

refs #4560

Change-Id: I88d2ba28623b051929a50043c0a46e6a4c6ac7fb
diff --git a/src/name-component.cpp b/src/name-component.cpp
index bd551b2..893a852 100644
--- a/src/name-component.cpp
+++ b/src/name-component.cpp
@@ -30,7 +30,6 @@
 #include "util/sha256.hpp"
 #include "util/string-helper.hpp"
 
-#include <boost/algorithm/string/trim.hpp>
 #include <cstring>
 #include <sstream>
 
@@ -112,7 +111,6 @@
 Component
 Component::fromEscapedString(std::string input)
 {
-  boost::algorithm::trim(input);
   uint32_t type = tlv::GenericNameComponent;
   size_t equalPos = input.find('=');
   if (equalPos != std::string::npos) {
diff --git a/src/name.cpp b/src/name.cpp
index d80fecf..7bbcc2b 100644
--- a/src/name.cpp
+++ b/src/name.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -30,7 +30,6 @@
 #include "util/time.hpp"
 
 #include <sstream>
-#include <boost/algorithm/string/trim.hpp>
 #include <boost/functional/hash.hpp>
 #include <boost/range/adaptor/reversed.hpp>
 #include <boost/range/concepts.hpp>
@@ -71,7 +70,6 @@
 
 Name::Name(std::string uri)
 {
-  boost::algorithm::trim(uri);
   if (uri.empty())
     return;
 
@@ -82,7 +80,6 @@
     if (iFirstSlash == std::string::npos || iColon < iFirstSlash) {
       // Omit the leading protocol such as ndn:
       uri.erase(0, iColon + 1);
-      boost::algorithm::trim(uri);
     }
   }
 
@@ -96,12 +93,10 @@
         return;
       else {
         uri.erase(0, iAfterAuthority + 1);
-        boost::algorithm::trim(uri);
       }
     }
     else {
       uri.erase(0, 1);
-      boost::algorithm::trim(uri);
     }
   }
 
diff --git a/tests/unit-tests/name.t.cpp b/tests/unit-tests/name.t.cpp
index 27b0255..c934be1 100644
--- a/tests/unit-tests/name.t.cpp
+++ b/tests/unit-tests/name.t.cpp
@@ -55,12 +55,36 @@
   BOOST_CHECK_EQUAL(decoded, name);
 }
 
-BOOST_AUTO_TEST_CASE(NameWithSpaces)
+BOOST_AUTO_TEST_CASE(ParseUri)
 {
-  Name name("/ hello\t/\tworld \r\n");
+  // URI with correct scheme
+  BOOST_CHECK_EQUAL(Name("ndn:/hello/world").toUri(), "/hello/world");
 
-  BOOST_CHECK_EQUAL("/hello/world", name);
+  // URI with incorrect scheme: auto-corrected
+  BOOST_CHECK_EQUAL(Name("ncc:/hello/world").toUri(), "/hello/world");
+
+  // URI with authority: authority ignored
+  BOOST_CHECK_EQUAL(Name("//authority/hello/world").toUri(), "/hello/world");
+  BOOST_CHECK_EQUAL(Name("ndn://authority/hello/world").toUri(), "/hello/world");
+
+  // URI containing unescaped characters: auto-corrected
+  BOOST_CHECK_EQUAL(Name("/ hello\t/\tworld \r\n").toUri(), "/%20hello%09/%09world%20%0D%0A");
+  BOOST_CHECK_EQUAL(Name("/hello/world/  ").toUri(), "/hello/world/%20%20");
+  BOOST_CHECK_EQUAL(Name("/:?#[]@").toUri(), "/%3A%3F%23%5B%5D%40");
+
+  // URI not starting with '/': accepted as PartialName
+  BOOST_CHECK_EQUAL(Name("").toUri(), "/");
+  BOOST_CHECK_EQUAL(Name(" ").toUri(), "/%20");
+  BOOST_CHECK_EQUAL(Name("  /hello/world").toUri(), "/%20%20/hello/world");
+  BOOST_CHECK_EQUAL(Name("hello/world").toUri(), "/hello/world");
+
+  // URI ending with '/': auto-corrected
+  BOOST_CHECK_EQUAL(Name("/hello/world/").toUri(), "/hello/world");
+
+  // URI containing bad component: rejected
   BOOST_CHECK_THROW(Name("/hello//world"), name::Component::Error);
+  BOOST_CHECK_THROW(Name("/hello/./world"), name::Component::Error);
+  BOOST_CHECK_THROW(Name("/hello/../world"), name::Component::Error);
 }
 
 BOOST_AUTO_TEST_CASE(DeepCopy)
@@ -104,7 +128,7 @@
 
   BOOST_CHECK_EQUAL("/hello/world", name.getSubName(0));
   BOOST_CHECK_EQUAL("/world", name.getSubName(1));
-  BOOST_CHECK_EQUAL("/hello/", name.getSubName(0, 1));
+  BOOST_CHECK_EQUAL("/hello", name.getSubName(0, 1));
 }
 
 BOOST_AUTO_TEST_CASE(SubNameNegativeIndex)