Skip to content

Commit

Permalink
Import of CFRANKS/HTML-FormFu-0.07003 from CPAN.
Browse files Browse the repository at this point in the history
gitpan-cpan-distribution: HTML-FormFu
gitpan-cpan-version:      0.07003
gitpan-cpan-path:         CFRANKS/HTML-FormFu-0.07003.tar.gz
gitpan-cpan-author:       CFRANKS
gitpan-cpan-maturity:     released
  • Loading branch information
Carl Franks authored and Gitpan committed Oct 26, 2014
1 parent 557c81a commit ce92d13
Show file tree
Hide file tree
Showing 20 changed files with 304 additions and 27 deletions.
17 changes: 17 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
0.07003 2010-08-02

- Fix: Group element now escapes each items attributes, label_attributes
and container attributes (based on by patch by Jeff Dairiki).

- Fix: If using default_natural, use default_datetime_args{set_time_zone}
if it's also set (Radek).

- Filter::HTMLScrubber extra functionality.

- Update _merge_hashes() so it can also merge arrays and hashes into a new
array. This is necessary to allow default_args() to define a different
ref-type than the element or processor which uses its values.

- Update Element::reCAPTCHA tests after changes to Captcha::reCAPTHCA
(bump dependency version).

0.07002 2010-06-24

- Fix: Use MRO::Compat before mro to support perl 5.8
Expand Down
8 changes: 8 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ t/elements/checkbox.t
t/elements/checkbox_force_default.t
t/elements/checkbox_retain_default.t
t/elements/checkboxgroup.t
t/elements/checkboxgroup_attributes_escaped.t
t/elements/checkboxgroup_attributes_escaped.yml
t/elements/combobox.t
t/elements/combobox.yml
t/elements/combobox_repeatable.t
Expand Down Expand Up @@ -446,6 +448,8 @@ t/elements/radio.t
t/elements/radio_force_default.t
t/elements/radio_retain_default.t
t/elements/radiogroup.t
t/elements/radiogroup_attributes_escaped.t
t/elements/radiogroup_attributes_escaped.yml
t/elements/radiogroup_attrs_xml.t
t/elements/radiogroup_dup_opt.t
t/elements/radiogroup_errors.t
Expand All @@ -467,6 +471,8 @@ t/elements/repeatable_repeatable.yml
t/elements/reset.t
t/elements/reverse.t
t/elements/select.t
t/elements/select_attributes_escaped.t
t/elements/select_attributes_escaped.yml
t/elements/select_deflator_default.t
t/elements/select_empty_first.t
t/elements/select_empty_first.yml
Expand Down Expand Up @@ -620,6 +626,8 @@ t/inflators/datetime_strptime.t
t/inflators/datetime_timezone.t
t/inflators/datetime_with_constraint.t
t/inflators/datetime_with_constraint.yml
t/internals/default_args-types.t
t/internals/default_args-types.yml
t/lib/HTMLFormFu/ElementSetup.pm
t/lib/HTMLFormFu/I18N.pm
t/lib/HTMLFormFu/I18N/en.pm
Expand Down
5 changes: 3 additions & 2 deletions META.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ no_index:
- t
- xt
requires:
Captcha::reCAPTCHA: 0.92
Captcha::reCAPTCHA: 0.93
Class::Accessor::Chained::Fast: 0
Clone: 0.31
Config::Any: 0.18
Expand Down Expand Up @@ -59,4 +59,5 @@ requires:
perl: 5.8.1
resources:
license: http://dev.perl.org/licenses/
version: 0.07002
repository: http://html-formfu.googlecode.com/svn/trunk/HTML-FormFu
version: 0.07003
4 changes: 3 additions & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ name 'HTML-FormFu';
perl_version '5.008001';
all_from 'lib/HTML/FormFu.pm';

repository 'http://html-formfu.googlecode.com/svn/trunk/HTML-FormFu';

# this is the lowest version of Exporter I can identify that exports import()
# it's bundled with perl 5.83
# version 5.567 that ships with perl 5.82 is no good
requires 'Exporter' => '5.57';

requires 'Captcha::reCAPTCHA' => 0.92;
requires 'Captcha::reCAPTCHA' => 0.93;
requires 'Class::Accessor::Chained::Fast';
requires 'Clone' => '0.31';
requires 'Config::Any' => '0.18'; # 0.10 - supports multi-doc config files
Expand Down
2 changes: 1 addition & 1 deletion lib/HTML/FormFu.pm
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ __PACKAGE__->mk_inherited_merging_accessors(qw( tt_args config_callback ));
*plugins = \&plugin;
*add_plugins = \&add_plugin;

our $VERSION = '0.07002';
our $VERSION = '0.07003';
$VERSION = eval $VERSION;

Class::C3::initialize();
Expand Down
17 changes: 15 additions & 2 deletions lib/HTML/FormFu/Element/Date.pm
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,21 @@ sub _date_defaults {
my $default;

if ( defined( $default = $self->default_natural ) ) {
my $parser = DateTime::Format::Natural->new;
$default = $parser->parse_datetime($default);
my $parser;

if ( defined( my $datetime_args = $self->default_datetime_args ) ) {
if ( exists $datetime_args->{set_time_zone} ) {
my $tz = $datetime_args->{set_time_zone};
$parser = DateTime::Format::Natural->new( time_zone => $tz );
}
else {
$parser = DateTime::Format::Natural->new;
}
}
else {
$parser = DateTime::Format::Natural->new;
}
$default = $parser->parse_datetime( $default );
}
elsif ( defined( $default = $self->default ) && length $default ) {

Expand Down
20 changes: 14 additions & 6 deletions lib/HTML/FormFu/Element/_Group.pm
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,11 @@ sub _quote_options {
my ( $self, $options ) = @_;

foreach my $opt (@$options) {
$opt->{label} = xml_escape( $opt->{label} );
$opt->{value} = xml_escape( $opt->{value} );
$opt->{label} = xml_escape( $opt->{label} );
$opt->{value} = xml_escape( $opt->{value} );
$opt->{attributes} = xml_escape( $opt->{attributes} );
$opt->{label_attributes} = xml_escape( $opt->{label_attributes} );
$opt->{container_attributes} = xml_escape( $opt->{container_attributes} );

if ( exists $opt->{group} ) {
$self->_quote_options( $opt->{group} );
Expand Down Expand Up @@ -473,8 +476,8 @@ Use to set the list of items in the select menu / radiogroup.
Its arguments must be an array-ref of items. Each item may be an array ref
of the form C<[ $value, $label ]> or a hash-ref of the form
C<< { value => $value, label => $label } >>. Each hash-ref may also have the
keys C<attributes> and C<label_attributes>.
C<< { value => $value, label => $label } >>. Each hash-ref may also have an
C<attributes> key.
Passing an item containing a C<group> key will, for
L<Select fields|HTML::FormFu::Element::Select>, create an optgroup. And for
Expand Down Expand Up @@ -504,11 +507,16 @@ variants of C<label> are supported, as are the C<value_xml> and C<value_loc>
variants of C<value>, the C<attributes_xml> variant of C<attributes> and the
C<label_attributes_xml> variant of C<label_attributes>.
C<container_attributes> or C<container_attributes_xml> is used by
C<container_attributes> / C<container_attributes_xml> is used by
L<HTML::FormFu::Element::Checkboxgroup> and
L<HTML::FormFu::Element::Radiogroup> for the c<span> surrounding each
item's input and label. It is ignored by L<HTML::FormFu::Element::Select>
elements.
elements.
C<label_attributes> / C<label_attributes_xml> is used by
L<HTML::FormFu::Element::Checkboxgroup> and
L<HTML::FormFu::Element::Radiogroup> for the c<label> tag of each item.
It is ignored by L<HTML::FormFu::Element::Select> elements.
=head2 values
Expand Down
21 changes: 18 additions & 3 deletions lib/HTML/FormFu/Filter/HTMLScrubber.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use mro 'c3';

use Clone ();

__PACKAGE__->mk_accessors(qw( allow ));
__PACKAGE__->mk_accessors(qw( allow comment default rules script ));

use HTML::Scrubber;

Expand All @@ -16,9 +16,13 @@ sub filter {

return if !defined $value;

my $allowed = $self->allow || [];
my %params = ( allow => 0 );
foreach (qw(allow comment default rules script)) {
my $val = $self->$_;
$params{$_} = $val if ( defined($val) );
}

my $scrubber = HTML::Scrubber->new( allow => $allowed );
my $scrubber = HTML::Scrubber->new(%params);

return $scrubber->scrub($value);
}
Expand Down Expand Up @@ -46,10 +50,21 @@ HTML::FormFu::Filter::HTMLScrubber - filter removing HTML markup
Remove HTML markup using L<HTML::Scrubber>.
All the functionality of L<HTML::Scrubber> can be accessed using
this module, other than the C<process> directive (which has a name
clash with the L<HTML::FormFu::Filter> framework).
For details of the filtering functionality see
L<HTML::Scrubber/allow>, L<HTML::Scrubber/comment>,
L<HTML::Scrubber/default>, L<HTML::Scrubber/rules> and
L<HTML::Scrubber/script>
=head1 AUTHOR
Carl Franks, C<cfranks@cpan.org>
Extended by Nigel Metheringham, C<nigelm@cpan.org>
Based on the original source code of L<HTML::Widget::Filter::HTMLStrip>, by
Lyo Kato, C<lyo.kato@gmail.com>
Expand Down
48 changes: 42 additions & 6 deletions lib/HTML/FormFu/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -494,19 +494,55 @@ sub _merge_hashes {

my %merged = %$lefthash;

while ( my ( $key, $value ) = each %$righthash ) {
my $is_right_ref = ref $value eq 'HASH';
my $is_left_ref = exists $lefthash->{$key} && ref $value eq 'HASH';
while ( my ( $key, $right_value ) = each %$righthash ) {

if ( $is_left_ref && $is_right_ref ) {
$merged{$key} = _merge_hashes( $lefthash->{$key}, $value );
my $left_value = $lefthash->{$key};

if ( exists $lefthash->{$key} ) {

my $is_left_ref = exists $lefthash->{$key}
&& ref $lefthash->{$key} eq 'HASH';

if ( ref $left_value eq 'HASH' && ref $right_value eq 'ARRAY' ) {
$merged{$key} = _merge_hash_array( $left_value, $right_value );
}
elsif ( ref $left_value eq 'ARRAY' && ref $right_value eq 'HASH' ) {
$merged{$key} = _merge_array_hash( $left_value, $right_value );
}
elsif ( ref $left_value eq 'ARRAY' && ref $right_value eq 'ARRAY' ) {
$merged{$key} = _merge_array_array( $left_value, $right_value );
}
elsif ( ref $left_value eq 'HASH' && ref $right_value eq 'HASH' ) {
$merged{$key} = _merge_hashes( $left_value, $right_value );
}
else {
$merged{$key} = $right_value;
}
}
else {
$merged{$key} = $value;
$merged{$key} = $right_value;
}
}

return \%merged;
}

sub _merge_hash_array {
my ( $left, $right ) = @_;

return [ $left, @$right ];
}

sub _merge_array_hash {
my ( $left, $right ) = @_;

return [ @$left, $right ];
}

sub _merge_array_array {
my ( $left, $right ) = @_;

return [ @$left, @$right ];
}

1;
29 changes: 29 additions & 0 deletions t/elements/checkboxgroup_attributes_escaped.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use strict;
use warnings;

use Test::More tests => 1;

use HTML::FormFu;

my $form = HTML::FormFu->new(
{ tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } );

$form->load_config_file('t/elements/checkboxgroup_attributes_escaped.yml');
$form->process;

my $field = $form->get_field('foo');

my $html = qq{<fieldset class="checkboxgroup">
<span>
<span myattr="escape&#38;container">
<input name="foo" type="checkbox" value="1" myattr="escape&#38;attr" />
<label myattr="escape&#38;label">First</label>
</span>
<span>
<input name="foo" type="checkbox" value="2" myattr="noescape&amp;" />
<label>Second</label>
</span>
</span>
</fieldset>};

is( "$field", $html );
18 changes: 18 additions & 0 deletions t/elements/checkboxgroup_attributes_escaped.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
elements:
- type: Checkboxgroup
name: foo
options:
- value: 1
label: 'First'
attributes:
myattr: 'escape&attr'
label_attributes:
myattr: 'escape&label'
container_attributes:
myattr: 'escape&container'

- value: 2
label: 'Second'
attributes_xml:
myattr: 'noescape&amp;'
8 changes: 5 additions & 3 deletions t/elements/date_default_datetime_args.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ $form->load_config_file('t/elements/date_default_datetime_args.yml');
$form->process;

{
my $parser = DateTime::Format::Natural->new;
my $dt = $parser->parse_datetime( 'now' );
$dt->set_time_zone( 'Europe/Berlin' );
my $parser = DateTime::Format::Natural->new(
time_zone => 'Europe/Berlin',
);

my $dt = $parser->parse_datetime( 'now' );

my $foo = $form->get_field('foo');

Expand Down
29 changes: 29 additions & 0 deletions t/elements/radiogroup_attributes_escaped.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use strict;
use warnings;

use Test::More tests => 1;

use HTML::FormFu;

my $form = HTML::FormFu->new(
{ tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } } );

$form->load_config_file('t/elements/radiogroup_attributes_escaped.yml');
$form->process;

my $field = $form->get_field('foo');

my $html = qq{<fieldset class="radiogroup">
<span>
<span myattr="escape&#38;container">
<input name="foo" type="radio" value="1" myattr="escape&#38;attr" />
<label myattr="escape&#38;label">First</label>
</span>
<span>
<input name="foo" type="radio" value="2" myattr="noescape&amp;" />
<label>Second</label>
</span>
</span>
</fieldset>};

is( "$field", $html );
18 changes: 18 additions & 0 deletions t/elements/radiogroup_attributes_escaped.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
elements:
- type: Radiogroup
name: foo
options:
- value: 1
label: 'First'
attributes:
myattr: 'escape&attr'
label_attributes:
myattr: 'escape&label'
container_attributes:
myattr: 'escape&container'

- value: 2
label: 'Second'
attributes_xml:
myattr: 'noescape&amp;'
4 changes: 2 additions & 2 deletions t/elements/recaptcha.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ my $form_xhtml = <<EOF;
var RecaptchaOptions = {};
//]]>
</script>
<script src="http://api.recaptcha.net/challenge?k=xxx" type="text/javascript"></script>
<noscript><iframe frameborder="0" height="300" src="http://api.recaptcha.net/noscript?k=xxx" width="500"></iframe><textarea cols="40" name="recaptcha_challenge_field" rows="3"></textarea><input name="recaptcha_response_field" type="hidden" value="manual_challenge" /></noscript>
<script src="http://www.google.com/recaptcha/api/challenge?k=xxx" type="text/javascript"></script>
<noscript><iframe frameborder="0" height="300" src="http://www.google.com/recaptcha/api/noscript?k=xxx" width="500"></iframe><textarea cols="40" name="recaptcha_challenge_field" rows="3"></textarea><input name="recaptcha_response_field" type="hidden" value="manual_challenge" /></noscript>
</span>
</div>
</form>
Expand Down
Loading

0 comments on commit ce92d13

Please sign in to comment.