You are here: Foswiki>Tasks Web>Item13963 (18 Feb 2017, GeorgeClark)Edit Attach

Item13963: Foswiki::Form::getField() might generate 'use of undefined value' warnings.

pencil
Priority: Low
Current State: Closed
Released In: 2.1.3
Target Release: patch
Applies To: Engine
Component: FoswikiForm
Branches: Release02x01 master
Reported By: VadimBelman
Waiting For:
Last Change By: GeorgeClark
In a situation when form is in construction stage and one of its fields has default value containing %SEARCH% which refers back to the same form getFields method would be called on an undone form object where there is no fields key defined yet. Though it doesn't generate a error message but this would cause dereferencing of an undef. Here is the proposed patch:

--- Form.pm.orig   2016-02-13 23:40:23.000000000 -0500
+++ Form.pm   2016-02-13 23:40:53.000000000 -0500
@@ -672,8 +672,10 @@

 sub getField {
     my ( $this, $name ) = @_;
-    foreach my $fieldDef ( @{ $this->{fields} } ) {
-        return $fieldDef if ( $fieldDef->{name} && $fieldDef->{name} eq $name );
+    if (defined $this->{fields}) {
+        foreach my $fieldDef ( @{ $this->{fields} } ) {
+            return $fieldDef if ( $fieldDef->{name} && $fieldDef->{name} eq $name );
+        }
     }
     return;
 }

-- VadimBelman - 14 Feb 2016

 

ItemTemplate edit

Summary Foswiki::Form::getField() might generate 'use of undefined value' warnings.
ReportedBy VadimBelman
Codebase 2.1.2, 2.1.1, 2.1.0, 2.0.3
SVN Range
AppliesTo Engine
Component FoswikiForm
Priority Low
CurrentState Closed
WaitingFor
Checkins distro:6afb147b43a7
TargetRelease patch
ReleasedIn 2.1.3
CheckinsOnBranches Release02x01 master
trunkCheckins
masterCheckins distro:6afb147b43a7
ItemBranchCheckins
Release02x01Checkins distro:6afb147b43a7
Release02x00Checkins
Release01x01Checkins
Topic revision: r5 - 18 Feb 2017, GeorgeClark - This page was cached on 16 Nov 2017 - 14:28.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License