[Rt-commit] rt branch, 4.0/sanity-check-url-config, updated. rt-3.9.7-1127-g71334f7

Shawn Moore sartak at bestpractical.com
Tue Dec 28 19:02:09 EST 2010


The branch, 4.0/sanity-check-url-config has been updated
       via  71334f7afa6e98157f10e287669b5cd0d9a5bdf9 (commit)
      from  ba7b2d4b4420d576d3a3ba1ab39fe6b960be3b40 (commit)

Summary of changes:
 lib/RT/Config.pm   |   20 ++++++++++++++++++++
 t/api/web-config.t |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)
 create mode 100644 t/api/web-config.t

- Log -----------------------------------------------------------------
commit 71334f7afa6e98157f10e287669b5cd0d9a5bdf9
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Dec 28 19:01:40 2010 -0500

    Warnings and tests for broken WebPath settings

diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 64798a2..4d5888e 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -536,6 +536,26 @@ our %META = (
                               'You can change the site default in your %Lifecycles config.');
         }
     },
+    WebPath => {
+        PostLoadCheck => sub {
+            my $self  = shift;
+            my $value = shift;
+
+            # "In most cases, you should leave $WebPath set to '' (an empty value)."
+            return unless $value;
+
+            # $WebPath requires a leading / but no trailing /, or it can be blank.
+            return if $value =~ m{^/.+[^/]$};
+
+            if ($value =~ m{/$}) {
+                $RT::Logger->error("The WebPath config option requires no trailing slash");
+            }
+
+            if ($value !~ m{^/}) {
+                $RT::Logger->error("The WebPath config option requires a leading slash");
+            }
+        },
+    },
 );
 my %OPTIONS = ();
 
diff --git a/t/api/web-config.t b/t/api/web-config.t
new file mode 100644
index 0000000..150784d
--- /dev/null
+++ b/t/api/web-config.t
@@ -0,0 +1,36 @@
+use strict;
+use warnings;
+use RT;
+use RT::Test nodb => 1, tests => 9;
+
+sub warnings_from {
+    my $option = shift;
+    my $value  = shift;
+
+    my @warnings;
+    local $SIG{__WARN__} = sub {
+        push @warnings, $_[0];
+    };
+
+    RT->Config->Set($option => $value);
+    RT->Config->PostLoadCheck;
+
+    return @warnings;
+}
+
+is(warnings_from(WebPath => ''), 0);
+is(warnings_from(WebPath => '/foo'), 0);
+
+my @w = warnings_from(WebPath => '/foo/');
+is(@w, 1);
+like($w[0], qr/The WebPath config option requires no trailing slash/);
+
+ at w = warnings_from(WebPath => 'foo');
+is(@w, 1);
+like($w[0], qr/The WebPath config option requires a leading slash/);
+
+ at w = warnings_from(WebPath => 'foo/');
+is(@w, 2);
+like($w[0], qr/The WebPath config option requires no trailing slash/);
+like($w[1], qr/The WebPath config option requires a leading slash/);
+

-----------------------------------------------------------------------


More information about the Rt-commit mailing list