Fix handling of URLs with no schema. 

BUG=google-url:29
TEST=GURLTest::NonURL
Patch by mnaganov@chromium.org
Review https://chromiumcodereview.appspot.com/10542140/


git-svn-id: http://google-url.googlecode.com/svn/trunk@176 8873c55e-713a-0410-88f8-23d9c3d90b1b
diff --git a/src/gurl_unittest.cc b/src/gurl_unittest.cc
index f62267f..23a5c45 100644
--- a/src/gurl_unittest.cc
+++ b/src/gurl_unittest.cc
@@ -182,6 +182,12 @@
   EXPECT_EQ("", url.ref());
 }
 
+TEST(GURLTest, NonURL) {
+  GURL url("random");
+  EXPECT_FALSE(url.is_valid());
+  EXPECT_EQ("random", url.possibly_invalid_spec());
+}
+
 TEST(GURLTest, Resolve) {
   // The tricky cases for relative URL resolving are tested in the
   // canonicalizer unit test. Here, we just test that the GURL integration
diff --git a/src/url_util.cc b/src/url_util.cc
index 382cec2..04c595a 100644
--- a/src/url_util.cc
+++ b/src/url_util.cc
@@ -178,8 +178,10 @@
 #endif
 
   url_parse::Component scheme;
-  if (!url_parse::ExtractScheme(spec, spec_len, &scheme))
+  if (!url_parse::ExtractScheme(spec, spec_len, &scheme)) {
+    AppendInvalidNarrowString(spec, 0, spec_len, output);
     return false;
+  }
 
   // This is the parsed version of the input URL, we have to canonicalize it
   // before storing it in our object.