示例#1
0
svn_error_t *
svn_opt__arg_canonicalize_url(const char **url_out, const char *url_in,
                              apr_pool_t *pool)
{
    const char *target;

    /* Convert to URI. */
    target = svn_path_uri_from_iri(url_in, pool);
    /* Auto-escape some ASCII characters. */
    target = svn_path_uri_autoescape(target, pool);

    /* The above doesn't guarantee a valid URI. */
    if (! svn_path_is_uri_safe(target))
        return svn_error_createf(SVN_ERR_BAD_URL, 0,
                                 _("URL '%s' is not properly URI-encoded"),
                                 target);

    /* Verify that no backpaths are present in the URL. */
    if (svn_path_is_backpath_present(target))
        return svn_error_createf(SVN_ERR_BAD_URL, 0,
                                 _("URL '%s' contains a '..' element"),
                                 target);

    /* strip any trailing '/' and collapse other redundant elements */
    target = svn_path_canonicalize(target, pool);

    *url_out = target;
    return SVN_NO_ERROR;
}
示例#2
0
svn_error_t *JNIUtil::preprocessPath(const char *&path, apr_pool_t *pool)
{
  /* URLs and wc-paths get treated differently. */
  if (svn_path_is_url(path))
    {
      /* No need to canonicalize a URL's case or path separators. */

      /* Convert to URI. */
      path = svn_path_uri_from_iri(path, pool);

      /* Auto-escape some ASCII characters. */
      path = svn_path_uri_autoescape(path, pool);

      /* The above doesn't guarantee a valid URI. */
      if (! svn_path_is_uri_safe(path))
        return svn_error_createf(SVN_ERR_BAD_URL, NULL,
                                 _("URL '%s' is not properly URI-encoded"),
                                 path);

      /* Verify that no backpaths are present in the URL. */
      if (svn_path_is_backpath_present(path))
        return svn_error_createf(SVN_ERR_BAD_URL, NULL,
                                 _("URL '%s' contains a '..' element"),
                                 path);

      /* strip any trailing '/' */
      path = svn_uri_canonicalize(path, pool);
    }
  else  /* not a url, so treat as a path */
    {
      /* Normalize path to subversion internal style */

      /* ### In Subversion < 1.6 this method on Windows actually tried
         to lookup the path on disk to fix possible invalid casings in
         the passed path. (An extremely expensive operation; especially
         on network drives).

         This 'feature'is now removed as it penalizes every correct
         path passed, and also breaks behavior of e.g.
           'svn status .' returns '!' file, because there is only a "File"
             on disk.
            But when you then call 'svn status file', you get '? File'.

         As JavaHL is designed to be platform independent I assume users
         don't want this broken behavior on non round-trippable paths, nor
         the performance penalty.
       */

      path = svn_dirent_internal_style(path, pool);

      /* For kicks and giggles, let's absolutize it. */
      SVN_ERR(svn_dirent_get_absolute(&path, path, pool));
    }

  return NULL;
}