[xml] Windows: relative paths on the command-line



Hi everyone,

A guy named Michael Kuzmin reported that xsltproc does not work with
relative Windows paths under certain circumstances. If the document being
processed is not in the current directory and you specify its path relative
to the current directory on the command line, libxslt is not able to
discover the base of the document. This results in not being able to load
any stylesheets which might be specified in a PI.

Dragging the thing through the debugger, I saw that the problem is, what
else, a backshlash or two. I am strongly against XML files which contain
native path specifications, but command-line is a different thing. Xsltproc
should be able to interpret a native path specification if given on the
command-line.

Since Daniel introduced the xmlNormalizeWindowsPath function in libxml, I
thought that solving the thing there would be the best thing. I modified the
function to slashify everything you pass to it anyway, no matter if it can
be recognised as a windows path or not. If the function cannot recognise a
windows path, it will duplicate the string, just like before, but will
replace every backslash with a slash before returning it to the caller.

That machination solved the problem and I dare to believe it didn't
introduce any new ones. The new function body follows this text. Please risk
a glance and if everything is fine, I'll commit that.

Ciao
Igor


-----------------------------------------------------

  xmlChar *
  xmlNormalizeWindowsPath(const xmlChar *path)
  {
      int len, i = 0, j;
      xmlChar *ret;

      if (path == NULL)
        return(NULL);

      len = xmlStrlen(path);
      if (!IS_WINDOWS_PATH(path)) {
        ret = xmlStrdup(path);
        if (ret == NULL)
            return(NULL);
        j = 0;
      } else {
        ret = xmlMalloc(len + 10);
        if (ret == NULL)
            return(NULL);
        ret[0] = 'f';
        ret[1] = 'i';
        ret[2] = 'l';
        ret[3] = 'e';
        ret[4] = ':';
        ret[5] = '/';
        ret[6] = '/';
        ret[7] = '/';
        j = 8;
      }

      while (i < len) {
        /* TODO: UTF8 conversion + URI escaping ??? */
        if (path[i] == '\\')
            ret[j] = '/';
        else
            ret[j] = path[i];
        i++;
        j++;
      }
      ret[j] = 0;

      return(ret);
  }





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