Fix for bug 143164: support URLs and URL paths better.

This commit is contained in:
myk%mozilla.org 2002-05-09 00:40:02 +00:00
Родитель c0df0103f4
Коммит bde29842eb
2 изменённых файлов: 56 добавлений и 14 удалений

Просмотреть файл

@ -102,6 +102,7 @@ my $READ_CVS_USERNAME = $config->get('READ_CVS_USERNAME');
my $READ_CVS_PASSWORD = $config->get('READ_CVS_PASSWORD');
my $WRITE_CVS_SERVER = $config->get('WRITE_CVS_SERVER');
my $WEB_BASE_URI = $config->get('WEB_BASE_URI');
my $WEB_BASE_URI_PATTERN = $config->get('WEB_BASE_URI_PATTERN');
my $WEB_BASE_PATH = $config->get('WEB_BASE_PATH');
# Store the home directory so we can get back to it after changing directories
@ -189,33 +190,53 @@ exit;
sub ValidateFile
{
$request->param("file")
# Make sure a path was entered.
my $file = $request->param("file");
$file
|| DisplayError("You must include the name of the file.")
&& exit;
my $file = $request->param("file");
# If the file name starts with the base URI for files on the web site, it is
# a URL and needs to be converted into a file path, which we do by removing
# the base URI and adding the base path.
if ($file =~ s/^\Q$WEB_BASE_URI\E(.*)$/$1/i) { $file = $WEB_BASE_PATH . $file }
# URL -> Path Conversion
# Collapse multiple consecutive slashes (i.e. dir//file.txt)
# into a single slash.
# Remove the absolute URI for files on the web site (if any)
# from the beginning of the path.
if ($WEB_BASE_URI_PATTERN) { $file =~ s/^$WEB_BASE_URI_PATTERN//i }
else { $file =~ s/^\Q$WEB_BASE_URI\E//i }
# Entire Path Issues
# Collapse multiple consecutive slashes (i.e. dir//file.txt) into a single slash.
$file =~ s:/{2,}:/:;
# If the filename (the last name in the path) contains no period, it is
# probably a directory, so add a slash.
# Beginning of Path Issues
# Remove a preceding slash.
$file =~ s:^/::;
# Add the base path of the file in the cvs repository if necessary.
# (i.e. if the user entered a URL or a path based on the URL).
if ($file !~ /^\Q$WEB_BASE_PATH\E/) { $file = $WEB_BASE_PATH . $file }
# End of Path Issues
# If the filename (the last name in the path) contains no period,
# it is probably a directory, so add a slash.
if ($file =~ m:^[^\./]+$: || $file =~ m:/[^\./]+$:) { $file .= "/" }
# If the file ends with a forward slash, it is a directory, so add
# the name of the default file.
# If the file ends with a forward slash, it is a directory,
# so add the name of the default file.
if ($file =~ m:/$:) { $file .= "index.html" }
# Set the file path.
$request->param("file", $file);
# Note: we don't need to validate further because CVS will tell us
# whether or not the filename is valid.
# Note: we don't need to make sure the file exists at this point
# because CVS will tell us that.
# Construct a URL to the file if possible.
my $url = $file;

Просмотреть файл

@ -12,3 +12,24 @@ READ_CVS_PASSWORD = anonymous
# The temporary directory into which files will be checked out
# before being committed. Don't add a trailing slash.
TEMP_DIR = /tmp/doctor
# For files accessible via the web, the absolute URI at which
# editable files are found. Used to convert file names to URLs
# and vice-versa. Add a trailing slash.
WEB_BASE_URI = http://www.mozilla.org/
# A regular expression matching the base URI, useful when
# files can exist at multiple locations on the web (i.e.
# web site mirrors or if the "www." in the URI is optional).
# Leave this blank if you have only one base URI.
# Note that only the base URI above will be used to reconstruct
# URLs from paths, since there is no way to derive a single
# base URI from this pattern.
WEB_BASE_URI_PATTERN = http:\/\/(www\.)?mozilla\.org\/
# For files accessible via the web, the path to those files
# in the CVS repository. Used to convert file names to URLs
# and vice-versa. Don't add a preceding slash, since this path
# is relative to the CVS root directory, but do add a trailing
# slash.
WEB_BASE_PATH = mozilla-org/html/