Item14461: Formfield select values containing entities will reset on next save.

pencil
Priority: Normal
Current State: Closed
Released In: 2.1.5
Target Release: patch
Applies To: Engine
Component: DataForms
Branches: Release02x01 master Item14288 Item14454
Reported By: GeorgeClark
Waiting For:
Last Change By: GeorgeClark
Related somewhat to Item12495. This shows up in our CountryList. For example, Curaça won't stick.

We can't ship this topic with unicode/utf8 characters, as the installed site might not be using utf-8.

I'm not sure what the fix is. Marking this for 2.1.5 though.

-- GeorgeClark - 21 Aug 2017

Korea, Democratic People's Republic of doesn't stick either due to the comma.

-- MichaelDaum - 21 Aug 2017

Michael, I've got a fix for both this issue, and Item12495.

First part of the patch ignores leading and trailing spaces when splitting the options values, and also does an entity decode.
diff --git a/core/lib/Foswiki/Form/ListFieldDefinition.pm b/core/lib/Foswiki/Form/ListFieldDefinition.pm
index 5625136..ad8d1bf 100644
--- a/core/lib/Foswiki/Form/ListFieldDefinition.pm
+++ b/core/lib/Foswiki/Form/ListFieldDefinition.pm
@@ -16,6 +16,7 @@ use warnings;
 use Assert;
 
 use Foswiki::Form::FieldDefinition ();
+use HTML::Entities;
 our @ISA = ('Foswiki::Form::FieldDefinition');
 
 BEGIN {
@@ -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};
@@ -100,6 +101,7 @@ sub getOptions {
         }
     }
     @vals = map { $_ =~ s/^\s*(.*)\s*$/$1/; $_; } @vals;
+    @vals = map { $_ = HTML::Entities::decode_entities( $_ ); } @vals;
 
     $this->{_descriptions} = \%descr;
 
And this patch doesn't parse commas in the value field when the formfield is not multi-valued. So if a formfield is both multi-valued and has embedded commas in values, it will still be a problem.]
diff --git a/core/lib/Foswiki/Form/Select.pm b/core/lib/Foswiki/Form/Select.pm
index ba0048c..2504146 100644
--- a/core/lib/Foswiki/Form/Select.pm
+++ b/core/lib/Foswiki/Form/Select.pm
@@ -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
Unit tests pass, and the country code seems to be working okay now, as does a formfield value search that was inserting spaces before commas. But I have no idea what corner cases this might run into. So not checking it in for now.

-- GeorgeClark - 22 Aug 2017

Decided to check this in. It needs more testing.

-- GeorgeClark - 14 Oct 2017

-- GeorgeClark - 14 Oct 2017
 

ItemTemplate edit

Summary Formfield select values containing entities will reset on next save.
ReportedBy GeorgeClark
Codebase 2.1.4, trunk
SVN Range
AppliesTo Engine
Component DataForms
Priority Normal
CurrentState Closed
WaitingFor
Checkins distro:73c907d38a0b
TargetRelease patch
ReleasedIn 2.1.5
CheckinsOnBranches Release02x01 master Item14288 Item14454
trunkCheckins
masterCheckins distro:73c907d38a0b
ItemBranchCheckins distro:73c907d38a0b
Release02x01Checkins distro:73c907d38a0b
Release02x00Checkins
Release01x01Checkins
Topic revision: r8 - 22 Jan 2018, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy