Don't validate for UTF-8 here. (#148420, Robert Ögren)
authorMatthias Clasen <mclasen@redhat.com>
Fri, 30 Jul 2004 19:00:01 +0000 (19:00 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Fri, 30 Jul 2004 19:00:01 +0000 (19:00 +0000)
2004-07-30  Matthias Clasen  <mclasen@redhat.com>

* glib/gconvert.c (g_unescape_uri_string): Don't validate
for UTF-8 here.  (#148420, Robert Ögren)

* tests/uri-test.c (run_roundtrip_tests): Add tests for
roundtrip compatibility. Going from filename to uri and
back should always give you the same filename back.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/gconvert.c
tests/uri-test.c

index 61a012c..8835bd2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2004-07-30  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/gconvert.c (g_unescape_uri_string): Don't validate
+       for UTF-8 here.  (#148420, Robert Ögren)
+
+       * tests/uri-test.c (run_roundtrip_tests): Add tests for 
+       roundtrip compatibility. Going from filename to uri and 
+       back should always give you the same filename back. 
+
 2004-07-28  Matthias Clasen  <mclasen@redhat.com>
 
        * tests/markups/valid-{9,10,11}.gmarkup: 
index 61a012c..8835bd2 100644 (file)
@@ -1,3 +1,12 @@
+2004-07-30  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/gconvert.c (g_unescape_uri_string): Don't validate
+       for UTF-8 here.  (#148420, Robert Ögren)
+
+       * tests/uri-test.c (run_roundtrip_tests): Add tests for 
+       roundtrip compatibility. Going from filename to uri and 
+       back should always give you the same filename back. 
+
 2004-07-28  Matthias Clasen  <mclasen@redhat.com>
 
        * tests/markups/valid-{9,10,11}.gmarkup: 
index 61a012c..8835bd2 100644 (file)
@@ -1,3 +1,12 @@
+2004-07-30  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/gconvert.c (g_unescape_uri_string): Don't validate
+       for UTF-8 here.  (#148420, Robert Ögren)
+
+       * tests/uri-test.c (run_roundtrip_tests): Add tests for 
+       roundtrip compatibility. Going from filename to uri and 
+       back should always give you the same filename back. 
+
 2004-07-28  Matthias Clasen  <mclasen@redhat.com>
 
        * tests/markups/valid-{9,10,11}.gmarkup: 
index 61a012c..8835bd2 100644 (file)
@@ -1,3 +1,12 @@
+2004-07-30  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/gconvert.c (g_unescape_uri_string): Don't validate
+       for UTF-8 here.  (#148420, Robert Ögren)
+
+       * tests/uri-test.c (run_roundtrip_tests): Add tests for 
+       roundtrip compatibility. Going from filename to uri and 
+       back should always give you the same filename back. 
+
 2004-07-28  Matthias Clasen  <mclasen@redhat.com>
 
        * tests/markups/valid-{9,10,11}.gmarkup: 
index 61a012c..8835bd2 100644 (file)
@@ -1,3 +1,12 @@
+2004-07-30  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/gconvert.c (g_unescape_uri_string): Don't validate
+       for UTF-8 here.  (#148420, Robert Ögren)
+
+       * tests/uri-test.c (run_roundtrip_tests): Add tests for 
+       roundtrip compatibility. Going from filename to uri and 
+       back should always give you the same filename back. 
+
 2004-07-28  Matthias Clasen  <mclasen@redhat.com>
 
        * tests/markups/valid-{9,10,11}.gmarkup: 
index e16ba1e..4dc1483 100644 (file)
@@ -1401,7 +1401,7 @@ g_unescape_uri_string (const char *escaped,
   g_assert (out - result <= len);
   *out = '\0';
 
-  if (in != in_end || !g_utf8_validate (result, -1, NULL))
+  if (in != in_end)
     {
       g_free (result);
       return NULL;
index b2ef5d5..86536e4 100644 (file)
@@ -127,10 +127,10 @@ from_uri_tests[] = {
   { "file://otherhost/etc", "/etc", "otherhost"},
   { "file://otherhost/etc/%23%25%20file", "/etc/#% file", "otherhost"},
   { "file://%C3%B6%C3%A4%C3%A5/etc", NULL, NULL, G_CONVERT_ERROR_BAD_URI},
-  { "file:////etc/%C3%B6%C3%C3%C3%A5", NULL, NULL, G_CONVERT_ERROR_BAD_URI},
-  { "file://localhost/\xE5\xE4\xF6", NULL, NULL, G_CONVERT_ERROR_BAD_URI},
+  { "file:////etc/%C3%B6%C3%C3%C3%A5", "//etc/\xc3\xb6\xc3\xc3\xc3\xa5", NULL},
+  { "file://localhost/\xE5\xE4\xF6", "/\xe5\xe4\xf6", "localhost"},
   { "file://\xE5\xE4\xF6/etc", NULL, NULL, G_CONVERT_ERROR_BAD_URI},
-  { "file://localhost/%E5%E4%F6", NULL, NULL, G_CONVERT_ERROR_BAD_URI},
+  { "file://localhost/%E5%E4%F6", "/\xe5\xe4\xf6", "localhost"},
   { "file://%E5%E4%F6/etc", NULL, NULL, G_CONVERT_ERROR_BAD_URI},
   { "file:///some/file#bad", NULL, NULL, G_CONVERT_ERROR_BAD_URI},
   { "file://some", NULL, NULL, G_CONVERT_ERROR_BAD_URI},
@@ -310,6 +310,68 @@ run_from_uri_tests (void)
   g_print ("\n");
 }
 
+static gint
+safe_strcmp (const gchar *a, const gchar *b)
+{
+  return strcmp (a ? a : "", b ? b : "");
+}
+
+static void
+run_roundtrip_tests (void)
+{
+  int i;
+  gchar *uri, *hostname, *res;
+  GError *error;
+  
+  for (i = 0; i < G_N_ELEMENTS (to_uri_tests); i++)
+    {
+      if (to_uri_tests[i].expected_error != 0)
+       continue;
+
+      error = NULL;
+      uri = g_filename_to_uri (to_uri_tests[i].filename,
+                              to_uri_tests[i].hostname,
+                              &error);
+      
+      if (error != NULL)
+       {
+         g_print ("g_filename_to_uri failed unexpectedly: %s\n", 
+                  error->message);
+         any_failed = TRUE;
+         continue;
+       }
+      
+      error = NULL;
+      res = g_filename_from_uri (uri, &hostname, &error);
+      if (error != NULL)
+       {
+         g_print ("g_filename_from_uri failed unexpectedly: %s\n", 
+                  error->message);
+         any_failed = TRUE;
+         continue;
+       }
+
+      if (safe_strcmp (to_uri_tests[i].filename, res))
+       {
+         g_message ("roundtrip test %d failed, filename modified: "
+                    " expected \"%s\", but got \"%s\"\n",
+                    i, to_uri_tests[i].filename, res);
+         any_failed = TRUE;
+       }
+
+      if (safe_strcmp (to_uri_tests[i].hostname, hostname))
+       {
+         g_print ("roundtrip test %d failed, hostname modified: "
+                    " expected \"%s\", but got \"%s\"\n",
+                  i, to_uri_tests[i].hostname, hostname);
+         any_failed = TRUE;
+       }
+
+      /* Give some output */
+      g_print (".");
+    }
+}
+
 int
 main (int   argc,
       char *argv[])
@@ -327,6 +389,7 @@ main (int   argc,
 
   run_to_uri_tests ();
   run_from_uri_tests ();
+  run_roundtrip_tests ();
 
   return any_failed ? 1 : 0;
 }