Not used on Windows, don't even compile it then.
authorTor Lillqvist <tml@iki.fi>
Wed, 23 Jan 2002 00:05:30 +0000 (00:05 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Wed, 23 Jan 2002 00:05:30 +0000 (00:05 +0000)
2002-01-23  Tor Lillqvist  <tml@iki.fi>

* glib/gconvert.c: (strdup_len): Not used on Windows, don't even
compile it then.

(acceptable): Improve comments for the _acceptable_ table: put
each ASCII char above the hex number for it.

(g_escape_file_uri): On Windows, turn backslashes in the file name
into plain ("forward") slashes.

(g_filename_from_uri): On Windows, don't return the hostname
"localhost", because we can not be 100% sure it will be recognized
in all cases anyway, so simpler to turn it into a null
hostname.

Change slashes in the filename into backslashes, as that is the
more canonical separator.

Recognize drive letters (either followed by a colon or a vertical
bar, as used by some browsers), and if the filename part starts
with a such, don't include any (back)slash.

Don't drop any extra leading slash in the filename on Unix.

(g_filename_to_uri): On Windows, if the hostname is "localhost",
don't use it, for consistency with g_filename_from_uri().

tests/uri-test.c: Change accordingly, so that all tests pass on
Windows. Unix, too, I hope, though I couldn't check that now.

(main): Unset the G_BROKEN_FILENAMES environment variable on Unix,
as some tests require that filenames are in UTF-8. Is unsetenv()
portable?

These changes should fix bugs #59387, #59652, #59657 and #59658.

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

index 45be83d..7e8339e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,40 @@
+2002-01-23  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gconvert.c: (strdup_len): Not used on Windows, don't even
+       compile it then.
+
+       (acceptable): Improve comments for the _acceptable_ table: put
+       each ASCII char above the hex number for it.
+
+       (g_escape_file_uri): On Windows, turn backslashes in the file name
+       into plain ("forward") slashes.
+
+       (g_filename_from_uri): On Windows, don't return the hostname
+       "localhost", because we can not be 100% sure it will be recognized
+       in all cases anyway, so simpler to turn it into a null
+       hostname. 
+
+       Change slashes in the filename into backslashes, as that is the
+       more canonical separator.
+
+       Recognize drive letters (either followed by a colon or a vertical
+       bar, as used by some browsers), and if the filename part starts
+       with a such, don't include any (back)slash.
+
+       Don't drop any extra leading slash in the filename on Unix.
+
+       (g_filename_to_uri): On Windows, if the hostname is "localhost",
+       don't use it, for consistency with g_filename_from_uri().
+       
+       tests/uri-test.c: Change accordingly, so that all tests pass on
+       Windows. Unix, too, I hope, though I couldn't check that now.
+
+       (main): Unset the G_BROKEN_FILENAMES environment variable on Unix,
+       as some tests require that filenames are in UTF-8. Is unsetenv()
+       portable?
+
+       These changes should fix bugs #59387, #59652, #59657 and #59658.
+       
 2002-01-22  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * configure.in: Get the right multithread option for GCC 3.0 and
index 45be83d..7e8339e 100644 (file)
@@ -1,3 +1,40 @@
+2002-01-23  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gconvert.c: (strdup_len): Not used on Windows, don't even
+       compile it then.
+
+       (acceptable): Improve comments for the _acceptable_ table: put
+       each ASCII char above the hex number for it.
+
+       (g_escape_file_uri): On Windows, turn backslashes in the file name
+       into plain ("forward") slashes.
+
+       (g_filename_from_uri): On Windows, don't return the hostname
+       "localhost", because we can not be 100% sure it will be recognized
+       in all cases anyway, so simpler to turn it into a null
+       hostname. 
+
+       Change slashes in the filename into backslashes, as that is the
+       more canonical separator.
+
+       Recognize drive letters (either followed by a colon or a vertical
+       bar, as used by some browsers), and if the filename part starts
+       with a such, don't include any (back)slash.
+
+       Don't drop any extra leading slash in the filename on Unix.
+
+       (g_filename_to_uri): On Windows, if the hostname is "localhost",
+       don't use it, for consistency with g_filename_from_uri().
+       
+       tests/uri-test.c: Change accordingly, so that all tests pass on
+       Windows. Unix, too, I hope, though I couldn't check that now.
+
+       (main): Unset the G_BROKEN_FILENAMES environment variable on Unix,
+       as some tests require that filenames are in UTF-8. Is unsetenv()
+       portable?
+
+       These changes should fix bugs #59387, #59652, #59657 and #59658.
+       
 2002-01-22  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * configure.in: Get the right multithread option for GCC 3.0 and
index 45be83d..7e8339e 100644 (file)
@@ -1,3 +1,40 @@
+2002-01-23  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gconvert.c: (strdup_len): Not used on Windows, don't even
+       compile it then.
+
+       (acceptable): Improve comments for the _acceptable_ table: put
+       each ASCII char above the hex number for it.
+
+       (g_escape_file_uri): On Windows, turn backslashes in the file name
+       into plain ("forward") slashes.
+
+       (g_filename_from_uri): On Windows, don't return the hostname
+       "localhost", because we can not be 100% sure it will be recognized
+       in all cases anyway, so simpler to turn it into a null
+       hostname. 
+
+       Change slashes in the filename into backslashes, as that is the
+       more canonical separator.
+
+       Recognize drive letters (either followed by a colon or a vertical
+       bar, as used by some browsers), and if the filename part starts
+       with a such, don't include any (back)slash.
+
+       Don't drop any extra leading slash in the filename on Unix.
+
+       (g_filename_to_uri): On Windows, if the hostname is "localhost",
+       don't use it, for consistency with g_filename_from_uri().
+       
+       tests/uri-test.c: Change accordingly, so that all tests pass on
+       Windows. Unix, too, I hope, though I couldn't check that now.
+
+       (main): Unset the G_BROKEN_FILENAMES environment variable on Unix,
+       as some tests require that filenames are in UTF-8. Is unsetenv()
+       portable?
+
+       These changes should fix bugs #59387, #59652, #59657 and #59658.
+       
 2002-01-22  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * configure.in: Get the right multithread option for GCC 3.0 and
index 45be83d..7e8339e 100644 (file)
@@ -1,3 +1,40 @@
+2002-01-23  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gconvert.c: (strdup_len): Not used on Windows, don't even
+       compile it then.
+
+       (acceptable): Improve comments for the _acceptable_ table: put
+       each ASCII char above the hex number for it.
+
+       (g_escape_file_uri): On Windows, turn backslashes in the file name
+       into plain ("forward") slashes.
+
+       (g_filename_from_uri): On Windows, don't return the hostname
+       "localhost", because we can not be 100% sure it will be recognized
+       in all cases anyway, so simpler to turn it into a null
+       hostname. 
+
+       Change slashes in the filename into backslashes, as that is the
+       more canonical separator.
+
+       Recognize drive letters (either followed by a colon or a vertical
+       bar, as used by some browsers), and if the filename part starts
+       with a such, don't include any (back)slash.
+
+       Don't drop any extra leading slash in the filename on Unix.
+
+       (g_filename_to_uri): On Windows, if the hostname is "localhost",
+       don't use it, for consistency with g_filename_from_uri().
+       
+       tests/uri-test.c: Change accordingly, so that all tests pass on
+       Windows. Unix, too, I hope, though I couldn't check that now.
+
+       (main): Unset the G_BROKEN_FILENAMES environment variable on Unix,
+       as some tests require that filenames are in UTF-8. Is unsetenv()
+       portable?
+
+       These changes should fix bugs #59387, #59652, #59657 and #59658.
+       
 2002-01-22  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * configure.in: Get the right multithread option for GCC 3.0 and
index 45be83d..7e8339e 100644 (file)
@@ -1,3 +1,40 @@
+2002-01-23  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gconvert.c: (strdup_len): Not used on Windows, don't even
+       compile it then.
+
+       (acceptable): Improve comments for the _acceptable_ table: put
+       each ASCII char above the hex number for it.
+
+       (g_escape_file_uri): On Windows, turn backslashes in the file name
+       into plain ("forward") slashes.
+
+       (g_filename_from_uri): On Windows, don't return the hostname
+       "localhost", because we can not be 100% sure it will be recognized
+       in all cases anyway, so simpler to turn it into a null
+       hostname. 
+
+       Change slashes in the filename into backslashes, as that is the
+       more canonical separator.
+
+       Recognize drive letters (either followed by a colon or a vertical
+       bar, as used by some browsers), and if the filename part starts
+       with a such, don't include any (back)slash.
+
+       Don't drop any extra leading slash in the filename on Unix.
+
+       (g_filename_to_uri): On Windows, if the hostname is "localhost",
+       don't use it, for consistency with g_filename_from_uri().
+       
+       tests/uri-test.c: Change accordingly, so that all tests pass on
+       Windows. Unix, too, I hope, though I couldn't check that now.
+
+       (main): Unset the G_BROKEN_FILENAMES environment variable on Unix,
+       as some tests require that filenames are in UTF-8. Is unsetenv()
+       portable?
+
+       These changes should fix bugs #59387, #59652, #59657 and #59658.
+       
 2002-01-22  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * configure.in: Get the right multithread option for GCC 3.0 and
index 45be83d..7e8339e 100644 (file)
@@ -1,3 +1,40 @@
+2002-01-23  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gconvert.c: (strdup_len): Not used on Windows, don't even
+       compile it then.
+
+       (acceptable): Improve comments for the _acceptable_ table: put
+       each ASCII char above the hex number for it.
+
+       (g_escape_file_uri): On Windows, turn backslashes in the file name
+       into plain ("forward") slashes.
+
+       (g_filename_from_uri): On Windows, don't return the hostname
+       "localhost", because we can not be 100% sure it will be recognized
+       in all cases anyway, so simpler to turn it into a null
+       hostname. 
+
+       Change slashes in the filename into backslashes, as that is the
+       more canonical separator.
+
+       Recognize drive letters (either followed by a colon or a vertical
+       bar, as used by some browsers), and if the filename part starts
+       with a such, don't include any (back)slash.
+
+       Don't drop any extra leading slash in the filename on Unix.
+
+       (g_filename_to_uri): On Windows, if the hostname is "localhost",
+       don't use it, for consistency with g_filename_from_uri().
+       
+       tests/uri-test.c: Change accordingly, so that all tests pass on
+       Windows. Unix, too, I hope, though I couldn't check that now.
+
+       (main): Unset the G_BROKEN_FILENAMES environment variable on Unix,
+       as some tests require that filenames are in UTF-8. Is unsetenv()
+       portable?
+
+       These changes should fix bugs #59387, #59652, #59657 and #59658.
+       
 2002-01-22  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * configure.in: Get the right multithread option for GCC 3.0 and
index 45be83d..7e8339e 100644 (file)
@@ -1,3 +1,40 @@
+2002-01-23  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gconvert.c: (strdup_len): Not used on Windows, don't even
+       compile it then.
+
+       (acceptable): Improve comments for the _acceptable_ table: put
+       each ASCII char above the hex number for it.
+
+       (g_escape_file_uri): On Windows, turn backslashes in the file name
+       into plain ("forward") slashes.
+
+       (g_filename_from_uri): On Windows, don't return the hostname
+       "localhost", because we can not be 100% sure it will be recognized
+       in all cases anyway, so simpler to turn it into a null
+       hostname. 
+
+       Change slashes in the filename into backslashes, as that is the
+       more canonical separator.
+
+       Recognize drive letters (either followed by a colon or a vertical
+       bar, as used by some browsers), and if the filename part starts
+       with a such, don't include any (back)slash.
+
+       Don't drop any extra leading slash in the filename on Unix.
+
+       (g_filename_to_uri): On Windows, if the hostname is "localhost",
+       don't use it, for consistency with g_filename_from_uri().
+       
+       tests/uri-test.c: Change accordingly, so that all tests pass on
+       Windows. Unix, too, I hope, though I couldn't check that now.
+
+       (main): Unset the G_BROKEN_FILENAMES environment variable on Unix,
+       as some tests require that filenames are in UTF-8. Is unsetenv()
+       portable?
+
+       These changes should fix bugs #59387, #59652, #59657 and #59658.
+       
 2002-01-22  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * configure.in: Get the right multithread option for GCC 3.0 and
index 45be83d..7e8339e 100644 (file)
@@ -1,3 +1,40 @@
+2002-01-23  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gconvert.c: (strdup_len): Not used on Windows, don't even
+       compile it then.
+
+       (acceptable): Improve comments for the _acceptable_ table: put
+       each ASCII char above the hex number for it.
+
+       (g_escape_file_uri): On Windows, turn backslashes in the file name
+       into plain ("forward") slashes.
+
+       (g_filename_from_uri): On Windows, don't return the hostname
+       "localhost", because we can not be 100% sure it will be recognized
+       in all cases anyway, so simpler to turn it into a null
+       hostname. 
+
+       Change slashes in the filename into backslashes, as that is the
+       more canonical separator.
+
+       Recognize drive letters (either followed by a colon or a vertical
+       bar, as used by some browsers), and if the filename part starts
+       with a such, don't include any (back)slash.
+
+       Don't drop any extra leading slash in the filename on Unix.
+
+       (g_filename_to_uri): On Windows, if the hostname is "localhost",
+       don't use it, for consistency with g_filename_from_uri().
+       
+       tests/uri-test.c: Change accordingly, so that all tests pass on
+       Windows. Unix, too, I hope, though I couldn't check that now.
+
+       (main): Unset the G_BROKEN_FILENAMES environment variable on Unix,
+       as some tests require that filenames are in UTF-8. Is unsetenv()
+       portable?
+
+       These changes should fix bugs #59387, #59652, #59657 and #59658.
+       
 2002-01-22  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * configure.in: Get the right multithread option for GCC 3.0 and
index e8adccd..c970e43 100644 (file)
@@ -623,6 +623,8 @@ g_convert_with_fallback (const gchar *str,
  * 
  */
 
+#ifndef G_PLATFORM_WIN32
+
 static gchar *
 strdup_len (const gchar *string,
            gssize       len,
@@ -663,6 +665,8 @@ strdup_len (const gchar *string,
   return g_strndup (string, real_len);
 }
 
+#endif
+
 /**
  * g_locale_to_utf8:
  * @opsysstring:   a string in the encoding of the current locale
@@ -1069,13 +1073,19 @@ typedef enum {
 } UnsafeCharacterSet;
 
 static const guchar acceptable[96] = {
- /* X0   X1   X2   X3   X4   X5   X6   X7   X8   X9   XA   XB   XC   XD   XE   XF */
-  0x00,0x3F,0x20,0x20,0x20,0x00,0x2C,0x3F,0x3F,0x3F,0x3F,0x22,0x20,0x3F,0x3F,0x1C, /* 2X  !"#$%&'()*+,-./   */
-  0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x38,0x20,0x20,0x2C,0x20,0x2C, /* 3X 0123456789:;<=>?   */
-  0x30,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F, /* 4X @ABCDEFGHIJKLMNO   */
-  0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x20,0x3F, /* 5X PQRSTUVWXYZ[\]^_   */
-  0x20,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F, /* 6X `abcdefghijklmno   */
-  0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x3F,0x20  /* 7X pqrstuvwxyz{|}~DEL */
+  /* A table of the ASCII chars from space (32) to DEL (127) */
+  /*      !    "    #    $    %    &    '    (    )    *    +    ,    -    .    / */ 
+  0x00,0x3F,0x20,0x20,0x20,0x00,0x2C,0x3F,0x3F,0x3F,0x3F,0x22,0x20,0x3F,0x3F,0x1C,
+  /* 0    1    2    3    4    5    6    7    8    9    :    ;    <    =    >    ? */
+  0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x38,0x20,0x20,0x2C,0x20,0x2C,
+  /* @    A    B    C    D    E    F    G    H    I    J    K    L    M    N    O */
+  0x30,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
+  /* P    Q    R    S    T    U    V    W    X    Y    Z    [    \    ]    ^    _ */
+  0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x20,0x3F,
+  /* `    a    b    c    d    e    f    g    h    i    j    k    l    m    n    o */
+  0x20,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
+  /* p    q    r    s    t    u    v    w    x    y    z    {    |    }    ~  DEL */
+  0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x20,0x20,0x20,0x3F,0x20
 };
 
 static const gchar hex[16] = "0123456789ABCDEF";
@@ -1106,7 +1116,7 @@ g_escape_uri_string (const gchar *string,
   use_mask = mask;
   for (p = string; *p != '\0'; p++)
     {
-      c = *p;
+      c = (guchar) *p;
       if (!ACCEPTABLE (c)) 
        unacceptable++;
     }
@@ -1116,7 +1126,7 @@ g_escape_uri_string (const gchar *string,
   use_mask = mask;
   for (q = result, p = string; *p != '\0'; p++)
     {
-      c = (unsigned char)*p;
+      c = (guchar) *p;
       
       if (!ACCEPTABLE (c))
        {
@@ -1142,6 +1152,23 @@ g_escape_file_uri (const gchar *hostname,
   char *escaped_path;
   char *res;
 
+#ifdef G_OS_WIN32
+  char *p, *backslash;
+
+  /* Turn backslashes into forward slashes. That's what Netscape
+   * does, and they are actually more or less equivalent in Windows.
+   */
+  
+  pathname = g_strdup (pathname);
+  p = (char *) pathname;
+  
+  while ((backslash = strchr (p, '\\')) != NULL)
+    {
+      *backslash = '/';
+      p = backslash + 1;
+    }
+#endif
+
   if (hostname && *hostname != '\0')
     {
       escaped_hostname = g_escape_uri_string (hostname, UNSAFE_HOST);
@@ -1155,6 +1182,10 @@ g_escape_file_uri (const gchar *hostname,
                     escaped_path,
                     NULL);
 
+#ifdef G_OS_WIN32
+  g_free ((char *) pathname);
+#endif
+
   g_free (escaped_hostname);
   g_free (escaped_path);
   
@@ -1256,6 +1287,9 @@ g_filename_from_uri (const char *uri,
   char *result;
   char *filename;
   int offs;
+#ifdef G_OS_WIN32
+  char *p, *slash;
+#endif
 
   if (hostname)
     *hostname = NULL;
@@ -1320,11 +1354,39 @@ g_filename_from_uri (const char *uri,
       return NULL;
     }
 
-  /* DOS uri's are like "file://host/c:\foo", so we need to check if we need to
-   * drop the initial slash */
   offs = 0;
-  if (g_path_is_absolute (filename+1))
-    offs = 1;
+#ifdef G_OS_WIN32
+  /* Drop localhost */
+  if (hostname && *hostname != NULL &&
+      g_ascii_strcasecmp (*hostname, "localhost") == 0)
+    {
+      g_free (*hostname);
+      *hostname = NULL;
+    }
+
+  /* Turn slashes into backslashes, because that's the canonical spelling */
+  p = filename;
+  while ((slash = strchr (p, '/')) != NULL)
+    {
+      *slash = '\\';
+      p = slash + 1;
+    }
+
+  /* Windows URIs with a drive letter can be like "file://host/c:/foo"
+   * or "file://host/c|/foo" (some Netscape versions). In those cases, start
+   * the filename from the drive letter.
+   */
+  if (g_ascii_isalpha (filename[1]))
+    {
+      if (filename[2] == ':')
+       offs = 1;
+      else if (filename[2] == '|')
+       {
+         filename[2] = ':';
+         offs = 1;
+       }
+    }
+#endif
   
   result = g_filename_from_utf8 (filename + offs, -1, NULL, NULL, error);
   g_free (filename);
@@ -1376,6 +1438,12 @@ g_filename_to_uri   (const char *filename,
       return NULL;
     }
   
+#ifdef G_OS_WIN32
+  /* Don't use localhost unnecessarily */
+  if (hostname && g_ascii_strcasecmp (hostname, "localhost") == 0)
+    hostname = NULL;
+#endif
+
   escaped_uri = g_escape_file_uri (hostname,
                                   utf8_filename);
   g_free (utf8_filename);
index 6b2baa4..6ca1b16 100644 (file)
@@ -44,20 +44,28 @@ ToUriTest
 to_uri_tests[] = {
   { "/etc", NULL, "file:///etc"},
   { "/etc", "", "file:///etc"},
-  { "/etc", "localhost", "file://localhost/etc"},
   { "/etc", "otherhost", "file://otherhost/etc"},
 #ifdef G_OS_WIN32
-  { "c:\\windows", NULL, "file:///c:\\windows"}, /* these 3 tests almost certainly fail */
-  { "c:\\windows", "localhost", "file://localhost/c:\\windows"},
-  { "c:\\windows", "otherhost", "file://otherhost/c:\\windows"},
+  { "/etc", "localhost", "file:///etc"},
+  { "c:\\windows", NULL, "file:///c:/windows"},
+  { "c:\\windows", "localhost", "file:///c:/windows"},
+  { "c:\\windows", "otherhost", "file://otherhost/c:/windows"},
+  { "\\\\server\\share\\dir", NULL, "file:////server/share/dir"},
+  { "\\\\server\\share\\dir", "localhost", "file:////server/share/dir"},
 #else
+  { "/etc", "localhost", "file://localhost/etc"},
   { "c:\\windows", NULL, NULL, G_CONVERT_ERROR_NOT_ABSOLUTE_PATH}, /* it's important to get this error on Unix */
   { "c:\\windows", "localhost", NULL, G_CONVERT_ERROR_NOT_ABSOLUTE_PATH},
   { "c:\\windows", "otherhost", NULL, G_CONVERT_ERROR_NOT_ABSOLUTE_PATH},
 #endif
   { "etc", "localhost", NULL, G_CONVERT_ERROR_NOT_ABSOLUTE_PATH},
+#ifndef G_OS_WIN32
+  /* g_filename_to_utf8 uses current code page on Win32, these tests assume that
+   * local filenames *are* in UTF-8.
+   */
   { "/etc/öäå", NULL, NULL, G_CONVERT_ERROR_ILLEGAL_SEQUENCE},
   { "/etc/öäå", NULL, "file:///etc/%C3%B6%C3%A4%C3%A5"},
+#endif
   { "/etc", "öäå", "file://%C3%B6%C3%A4%C3%A5/etc"},
   { "/etc", "åäö", NULL, G_CONVERT_ERROR_ILLEGAL_SEQUENCE},
   { "/etc/file with #%", NULL, "file:///etc/file%20with%20%23%25"},
@@ -69,9 +77,18 @@ to_uri_tests[] = {
   { "/ABCDEFGHIJKLMNOPQRSTUVWXYZ", NULL, "file:///ABCDEFGHIJKLMNOPQRSTUVWXYZ"},
   { "/abcdefghijklmnopqrstuvwxyz", NULL, "file:///abcdefghijklmnopqrstuvwxyz"},
   { "/-_.!~*'()", NULL, "file:///-_.!~*'()"},
+#ifdef G_OS_WIN32
+  /* As '\\' is a path separator on Win32, it gets turned into '/' in the URI */
+  { "/\"#%<>[\\]^`{|}\x7F", NULL, "file:///%22%23%25%3C%3E%5B/%5D%5E%60%7B%7C%7D%7F"},
+#else
+  /* On Unix, '\\' is a normal character in the file name */
   { "/\"#%<>[\\]^`{|}\x7F", NULL, "file:///%22%23%25%3C%3E%5B%5C%5D%5E%60%7B%7C%7D%7F"},
+#endif
   { "/;@+$,", NULL, "file:///%3B%40%2B%24%2C"},
-  { "/:", NULL, "file:///:"}, /* not escaped even though reserved as side effect of DOS support -- is that really what we want on Unix? */
+  /* This and some of the following are of course as such illegal file names on Windows,
+   * and would not occur in real life.
+   */
+  { "/:", NULL, "file:///:"},
   { "/?&=", NULL, "file:///?&="}, /* these are not escaped and other reserved characters are -- is that really what we want? */
   { "/", "0123456789", "file://0123456789/"},
   { "/", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "file://ABCDEFGHIJKLMNOPQRSTUVWXYZ/"},
@@ -98,8 +115,16 @@ FromUriTest
 from_uri_tests[] = {
   { "file:///etc", "/etc"},
   { "file:/etc", "/etc"},
+#ifdef G_OS_WIN32
+  /* On Win32 we don't return "localhost" hostames, just in case
+   * it isn't recognized anyway.
+   */
+  { "file://localhost/etc", "/etc", NULL},
+  { "file://localhost/etc/%23%25%20file", "/etc/#% file", NULL},
+#else
   { "file://localhost/etc", "/etc", "localhost"},
   { "file://localhost/etc/%23%25%20file", "/etc/#% file", "localhost"},
+#endif
   { "file://otherhost/etc", "/etc", "otherhost"},
   { "file://otherhost/etc/%23%25%20file", "/etc/#% file", "otherhost"},
   { "file://%C3%B6%C3%A4%C3%A5/etc", "/etc", "öäå"},
@@ -111,11 +136,22 @@ from_uri_tests[] = {
   { "", NULL, NULL, G_CONVERT_ERROR_BAD_URI},
   { "file:test", NULL, NULL, G_CONVERT_ERROR_BAD_URI},
   { "http://www.yahoo.com/", NULL, NULL, G_CONVERT_ERROR_BAD_URI},
-  { "file:////etc", "/etc"}, /* should be "//etc" -- mistake in code for DOS results in dropped slash */
-  { "file://///etc", "//etc"}, /* should be "///etc" -- mistake in code for DOS results in dropped slash */
-  { "file:///c:\\foo", "/c:\\foo"}, /* should be "c:\\foo" on DOS perhaps, but that would be bad for Unix */
-  { "file:///c:/foo", "/c:/foo"}, /* should be "c:/foo" on DOS perhaps, but that would be bad for Unix */
-  { "file:////c:/foo", "/c:/foo"}, /* should be "//c:/foo" on Unix */
+  { "file:////etc", "//etc"},
+  { "file://///etc", "///etc"},
+#ifdef G_OS_WIN32
+  /* URIs with backslashes come from some nonstandard application, but accept them anyhow */
+  { "file:///c:\\foo", "c:\\foo"},
+  { "file:///c:/foo\\bar", "c:\\foo\\bar"},
+  /* Accept also the old Netscape drive-letter-and-vertical bar convention */
+  { "file:///c|/foo", "c:\\foo"},
+  { "file:////server/share/dir", "\\\\server\\share\\dir"},
+  { "file://localhost//server/share/foo", "\\\\server\\share\\foo"},
+  { "file://otherhost//server/share/foo", "\\\\server\\share\\foo", "otherhost"},
+#else
+  { "file:///c:\\foo", "/c:\\foo"},
+  { "file:///c:/foo", "/c:/foo"},
+  { "file:////c:/foo", "//c:/foo"},
+#endif
   { "file://0123456789/", "/", "0123456789"},
   { "file://ABCDEFGHIJKLMNOPQRSTUVWXYZ/", "/", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"},
   { "file://abcdefghijklmnopqrstuvwxyz/", "/", "abcdefghijklmnopqrstuvwxyz"},
@@ -232,6 +268,16 @@ run_from_uri_tests (void)
        }
       else
        {
+#ifdef G_OS_WIN32
+         gchar *slash, *p;
+
+         p = from_uri_tests[i].expected_filename = g_strdup (from_uri_tests[i].expected_filename);
+         while ((slash = strchr (p, '/')) != NULL)
+           {
+             *slash = '\\';
+             p = slash + 1;
+           }
+#endif
          if (res == NULL || strcmp (res, from_uri_tests[i].expected_filename) != 0)
            {
              g_print ("\ng_filename_from_uri() test %d failed, expected result: %s, actual result: %s\n",
@@ -267,6 +313,10 @@ int
 main (int   argc,
       char *argv[])
 {
+#ifdef G_OS_UNIX
+  unsetenv ("G_BROKEN_FILENAMES");
+#endif
+
   run_to_uri_tests ();
   run_from_uri_tests ();