Skip to content

Fix Bugs in iif and getDate Functions in functionsfactory.ts #9674

Closed
@pistillo

Description

@pistillo

https://github.com/surveyjs/survey-library/blob/ddb1b9d479c93351aa6e9ee9cbff3d5b3c59dde4/packages/survey-core/src/functionsfactory.ts#L232C1-L243C55

Hi,

I have identified a couple of bugs in the iif and getDate functions defined in the file packages/survey-core/src/functionsfactory.ts. Below are the details:

1. iif Function

  • Bug: The condition if (!params && params.length !== 3) is incorrect. It should be if (!params || params.length !== 3) to correctly handle cases where params is null or undefined.
  • Current Code:
    function iif(params: any[]): any {
      if (!params && params.length !== 3) return "";
      return params[0] ? params[1] : params[2];
    }
  • Corrected Code:
    function iif(params: any[]): any {
      if (!params || params.length !== 3) return "";
      return params[0] ? params[1] : params[2];
    }

2. getDate Function

  • Bug: The condition if (!params && params.length < 1) is incorrect. It should be if (!params || params.length < 1) to correctly handle cases where params is null or undefined.
  • Current Code:
    function getDate(params: any[]): any {
      if (!params && params.length < 1) return null;
      if (!params[0]) return null;
      return createDate("function-getDate", params[0]);
    }
  • Corrected Code:
    function getDate(params: any[]): any {
      if (!params || params.length < 1) return null;
      if (!params[0]) return null;
      return createDate("function-getDate", params[0]);
    }

Metadata

Metadata

Assignees

Labels

user issueAn issue or bug reported by users

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions