Re: [xml] xmlNewInputFromFile URI problems on Win32



On 03.11.2006 21:28, Igor Zlatkovic wrote:
On 02.11.2006 09:31, Michael Day wrote:
Hi,

Ho,

When I call this on Windows:

     input = xmlNewInputFromFile(ctxt, "c:\\foo.xml");

the resulting input->filename looks like this:

     file:///c%3A/foo.html

Should the colon really be escaped?

Yes. See Daniel's answer to this.

Even worse, calling xmlPathToURI gives this:

     file%3A///c%253A/foo.html

This appears to have been doubly escaped. Are there some issues with URL handling on Windows?

Damn me. This is a godforsaken issue. I'll fix it tomorrow.

The attached patch removes the problem described above.

Still I don't really understand the whole wizardry which handles URIs, filesystem paths and conversions between the two. What is xmlCanonicPath actually meant to return?

Oh, if this fix is okay, could someone commit it? My CVS account has been deactivated so I cannot do it myself any longer.

Ciao,
Igor
Index: uri.c
===================================================================
RCS file: /cvs/gnome/libxml2/uri.c,v
retrieving revision 1.79
diff -c -r1.79 uri.c
*** uri.c       10 Oct 2006 12:37:14 -0000      1.79
--- uri.c       5 Nov 2006 17:35:50 -0000
***************
*** 2473,2478 ****
--- 2473,2496 ----
      cal = xmlCanonicPath(path);
      if (cal == NULL)
          return(NULL);
+ #if defined(_WIN32) && !defined(__CYGWIN__)
+     /* xmlCanonicPath can return an URI on Windows (is that the intended behaviour?) 
+        If 'cal' is a valid URI allready then we are done here, as continuing would make
+        it invalid. */
+     if ((uri = xmlParseURI((const char *) cal)) != NULL) {
+       xmlFreeURI(uri);
+       return cal;
+     }
+     /* 'cal' can contain a relative path with backslashes. If that is processed
+        by xmlSaveURI, they will be escaped and the external entity loader machinery
+        will fail. So convert them to slashes. Misuse 'ret' for walking. */
+     ret = cal;
+     while (*ret != '\0') {
+       if (*ret == '\\')
+           *ret = '/';
+       ret++;
+     }
+ #endif
      memset(&temp, 0, sizeof(temp));
      temp.path = (char *) cal;
      ret = xmlSaveUri(&temp);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]