[Html-widget] HTTP Constraint patch

Adam Herzog adam at herzogdesigns.com
Mon Jul 3 00:14:15 CEST 2006


H::W::C::HTTP invalidates empty fields.

This minor change (with a test) will let empty fields pass the HTTP
constraint. If the field is required, users should use an All
constraint as well.

Thanks,
-A

Index: t/constraint_http.t
===================================================================
--- t/constraint_http.t (revision 42)
+++ t/constraint_http.t (working copy)
@@ -1,4 +1,4 @@
-use Test::More tests => 7;
+use Test::More tests => 8;

 use_ok('HTML::Widget');

@@ -53,3 +53,14 @@
     my $f = $w->process($query);
     is( $f->valid('foo'), 0, "Invalid" );
 }
+
+# Empty should be valid
+{
+    my $query = HTMLWidget::TestLib->mock_query({ foo => '' });
+
+    my $f = $w->process($query);
+    is( "$f", <<EOF, 'XML output is filled out form' );
+<form id="widget" method="post"><fieldset><input class="textfield"
id="widget_foo" name="foo" type="text" /></fieldset></form>
+EOF
+}
+
Index: lib/HTML/Widget/Constraint/HTTP.pm
===================================================================
--- lib/HTML/Widget/Constraint/HTTP.pm  (revision 42)
+++ lib/HTML/Widget/Constraint/HTTP.pm  (working copy)
@@ -22,7 +22,7 @@

 =cut

-sub regex { qr/^s?https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+$/ }
+sub regex { qr/^(s?https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)?$/ }

 =head1 AUTHOR



More information about the Html-widget mailing list