Skip to content

Commit

Permalink
Item12495: Item14461: Fix issues with commas, entities in formfields
Browse files Browse the repository at this point in the history
 - When splitting a formfield value on commas, need to permit spaces.
 - entities need to be decoded when generating the values
 - if a formfield permits multiple-selections, don't allow embedded
   commas.  For single value select, then comma's are fine.

This corrects issues in the Country select box in the user form.
  • Loading branch information
gac410 committed Oct 14, 2017
1 parent 1c5967e commit 73c907d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion core/lib/Foswiki/Form/ListFieldDefinition.pm
Expand Up @@ -16,6 +16,7 @@ use warnings;
use Assert;

use Foswiki::Form::FieldDefinition ();
use HTML::Entities;
our @ISA = ('Foswiki::Form::FieldDefinition');

BEGIN {
Expand Down Expand Up @@ -58,7 +59,7 @@ sub getOptions {
my @vals = ();
my %descr = ();

@vals = split( /,/, $this->{value} );
@vals = split( /\s*,\s*/, $this->{value} );

if ( !scalar(@vals) ) {
my $topic = $this->{definingTopic} || $this->{name};
Expand Down Expand Up @@ -100,6 +101,7 @@ sub getOptions {
}
}
@vals = map { $_ =~ s/^\s*(.*)\s*$/$1/; $_; } @vals;
@vals = map { $_ = HTML::Entities::decode_entities($_); } @vals;

$this->{_descriptions} = \%descr;

Expand Down
8 changes: 7 additions & 1 deletion core/lib/Foswiki/Form/Select.pm
Expand Up @@ -97,7 +97,13 @@ sub renderForEdit {
my $choices = '';

$value = '' unless defined $value;
my %isSelected = map { $_ => 1 } split( /\s*,\s*/, $value );
my %isSelected;
if ( $this->isMultiValued() ) {
%isSelected = map { $_ => 1 } split( /\s*,\s*/, $value );
}
else {
$isSelected{$value} = 1;
}
foreach my $item ( @{ $this->getOptions() } ) {
my $option = $item
; # Item9647: make a copy not to modify the original value in the array
Expand Down

0 comments on commit 73c907d

Please sign in to comment.