whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [whimsy] branch master updated: Move URL validation to script: more flexible, and not all browsers support pattern validation fully
Date Tue, 07 Jun 2016 15:10:00 GMT
This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/whimsy.git

The following commit(s) were added to refs/heads/master by this push:
       new  2287062   Move URL validation to script: more flexible, and not all browsers support
pattern validation fully
       new  54a6c10   Merge branch 'master' of https://github.com/apache/whimsy.git
2287062 is described below

commit 2287062f50bda909fea1076fe23a994170e90f4e
Author: Sebb <sebb@apache.org>
AuthorDate: Tue Jun 7 16:07:23 2016 +0100

    Move URL validation to script: more flexible, and not all browsers
    support pattern validation fully
---
 tools/mirror_check.rb        | 24 ++++++++++++++++++++----
 www/members/mirror_check.cgi |  5 ++---
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/tools/mirror_check.rb b/tools/mirror_check.rb
index 1c01e4a..ff1c609 100755
--- a/tools/mirror_check.rb
+++ b/tools/mirror_check.rb
@@ -45,9 +45,7 @@ TODO - any more checks?
 
 $SAFE = 1
 
-DEFAULT = 'http://localhost/dist/'
-
-URLPAT = '^https?://[^/]+/(\S+/)?$'
+URLMATCH = %r!^https?://[^/]+/(\S+/)?$!i
 HTTPDIRS = %w(zzz/ mirror-tests/) # must exist
 HDRMATCH = %r!<h\d>Apache Software Foundation Distribution Meta-Directory</h\d>!
# must be on the zzz index page
 FTRMATCH = %r!This directory contains meta-data for the ASF mirroring system.! # must be
on the zzz index page
@@ -197,8 +195,24 @@ end
 
 # Suite: perform all the HTTP checks
 def checkHTTP(base)
+  # We don't check the pattern on the form for two reasons:
+  # - not all browsers support it
+  # - allows the input to be more flexible
+
+  # Fix up the URL
+  base += '/' unless base.end_with? '/'
+  base = 'http://' + base unless base.start_with? 'http'
+  # Now check the syntax:
+
   I "Checking #{base} ..."
 
+  unless URLMATCH.match(base)
+    F "Invalid URL syntax: #{base}"
+    return  
+  end
+
+  setup
+
   # Check the mirror time (and that zzz/ is readable)
   time = check_page(base, 'zzz/time.txt', severity = :F)
   if time
@@ -265,6 +279,9 @@ def init
   # build a list of validation errors
   @tests = []
   @fails = 0
+end
+
+def setup
   tlps = parseIndexPage(check_page('http://www.apache.org/dist/',''))
   podlings = parseIndexPage(check_page('http://www.apache.org/dist/incubator/',''))
   @pages = {:tlps => tlps, :podlings => podlings}
@@ -325,7 +342,6 @@ end
 if __FILE__ == $0
   init
   url = ARGV[0] || DEFAULT
-  url += '/' unless url.end_with? '/'
   checkHTTP(url)
   # display the test results
   @tests.each { |t| t.map{|k, v| puts "#{k}: - #{v}"}} 
diff --git a/www/members/mirror_check.cgi b/www/members/mirror_check.cgi
index c08e0de..75239a2 100755
--- a/www/members/mirror_check.cgi
+++ b/www/members/mirror_check.cgi
@@ -31,10 +31,9 @@ _html do
       _fieldset do
         _legend 'ASF Mirror Check Request'
         _ 'Mirror URL'
-        _input.name name: 'url', required: true, pattern: URLPAT,
+        _input.name name: 'url', required: true,
                     placeholder: 'mirror URL',
-                    size: 50, 
-                    value: DEFAULT
+                    size: 50
         _input type: 'submit', value: 'Check Mirror'
       end
     end

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <commits@whimsical.apache.org>'].

Mime
View raw message