/* Set *HANDLE to an open filehandle for a temporary file (i.e., automatically deleted when closed), into which the LOCK_TOKENS have been written out in the format described in the pre-commit hook template. LOCK_TOKENS is as returned by svn_fs__access_get_lock_tokens(). Allocate *HANDLE in POOL, and use POOL for temporary allocations. */ static svn_error_t * lock_token_content(apr_file_t **handle, apr_hash_t *lock_tokens, apr_pool_t *pool) { svn_stringbuf_t *lock_str = svn_stringbuf_create("LOCK-TOKENS:\n", pool); apr_hash_index_t *hi; for (hi = apr_hash_first(pool, lock_tokens); hi; hi = apr_hash_next(hi)) { void *val; const char *path, *token; apr_hash_this(hi, (void *)&token, NULL, &val); path = val; svn_stringbuf_appendstr(lock_str, svn_stringbuf_createf(pool, "%s|%s\n", svn_path_uri_autoescape(path, pool), token)); } svn_stringbuf_appendcstr(lock_str, "\n"); return create_temp_file(handle, svn_stringbuf__morph_into_string(lock_str), pool); }
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; }
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; }
std::string Url::escape(const char * url) { Pool pool; // First make sure % gets escaped std::string partlyEscaped(url); findAndReplace(partlyEscaped, "%", "%25"); // Let svn do the first part of the work partlyEscaped=svn_path_uri_autoescape(partlyEscaped.c_str(), pool); // Then worry about the rest findAndReplace(partlyEscaped, "#", "%23"); findAndReplace(partlyEscaped, ";", "%3B"); findAndReplace(partlyEscaped, "?", "%3F"); findAndReplace(partlyEscaped, "[", "%5B"); findAndReplace(partlyEscaped, "]", "%5D"); return partlyEscaped; }
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); #if '/' != SVN_PATH_LOCAL_SEPARATOR /* Allow using file:///C:\users\me/repos on Windows, like we did in 1.6 */ if (strchr(target, SVN_PATH_LOCAL_SEPARATOR)) { char *p = apr_pstrdup(pool, target); target = p; /* Convert all local-style separators to the canonical ones. */ for (; *p != '\0'; ++p) if (*p == SVN_PATH_LOCAL_SEPARATOR) *p = '/'; } #endif /* 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_uri_canonicalize(target, pool); *url_out = target; return SVN_NO_ERROR; }