Skip to content

DateHelper::parseString() receives null formatting parameter when processing exported JSON data #1655

@aedan-umd

Description

@aedan-umd

Description

Element -> parseDateAttribute() throws Exception if $formatting is NULL, but could default to 'auto'

When calling craft\feedme\services\Process->processFeed(...) from CLI using a JSON file generated by Craft export button.

In such a case where "$fieldInfo" does not list a $formatting attribute, craft\feedme\base\Element->parseDateAttribute(...) gets called with "$formatting == null" and throws an exception. It would instead be better if the default DateHelper::parseString(...) $formatting = 'auto' was used.

Steps to reproduce

  1. Export entries using Craft's default export button to create a JSON file
  2. Create a console controller with the following code:
    $element = $processService->processFeed($key, $feedSettings, $processedElementIds, $data);
    where $data contains entries parsed from the exported JSON file
  3. Run the console command
  4. Observe the TypeError exception

Expected Behavior

  • The date parsing should fall back to DateHelper::parseString() with 'auto' formatting when no formatting is specified.
    Actual Behavior
  • TypeError is thrown: craft\feedme\helpers\DateHelper::parseString(): Argument CSRF Protection #2 ($formatting) must be of type string, null given, called in feed-me/src/base/Element.php on line 352

Additional info

  • Craft version: 5.8.8
  • PHP version: 8.2
  • Database driver & version: MySQL 9.0.1
  • Plugins & versions: Feed-Me 6.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions