From bde29842eba0fac4d20e4ffaf60aa7bedc639a70 Mon Sep 17 00:00:00 2001 From: "myk%mozilla.org" Date: Thu, 9 May 2002 00:40:02 +0000 Subject: [PATCH] Fix for bug 143164: support URLs and URL paths better. --- webtools/doctor/doctor.cgi | 49 ++++++++++++++++++++++++++----------- webtools/doctor/sample.conf | 21 ++++++++++++++++ 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/webtools/doctor/doctor.cgi b/webtools/doctor/doctor.cgi index 47746688e599..66b635fc7755 100755 --- a/webtools/doctor/doctor.cgi +++ b/webtools/doctor/doctor.cgi @@ -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; diff --git a/webtools/doctor/sample.conf b/webtools/doctor/sample.conf index 2d4f3333511a..823f4efc7c04 100644 --- a/webtools/doctor/sample.conf +++ b/webtools/doctor/sample.conf @@ -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/