Explode plugin should allow null / empty strings

Created on 10 May 2024, 11 months ago

Problem/Motivation

Explode will fail if the input value is null by throwing an exception: Input should be a string.

However, when using this plugin with Feeds to fill a multi-value entity field, I think it's common that some entities will have several values, and others may have none. So an exception should not be thrown if the value is empty.

🐛 Bug report
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

🇯🇵Japan ptmkenny

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @ptmkenny
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 11 months ago
    534 pass
  • Status changed to Needs review 11 months ago
  • 🇯🇵Japan ptmkenny

    I fixed this for the Implode and Explode plugins by using the same logic as the StripTags plugin.

    But there are several other plugins that check is_string() and is_array() and throw an exception on an empty value.

    I think there should be a policy of whether tamper is expected to fail on an empty value or not.

    I would argue against failing on an empty value because you may want to import many entities, some of which have a field set and others that do not.

    This problem becomes obvious when importing via JSON with feeds_ex, as JSON objects may not have certain keys (that are set to be tampered with), and so when the JSON object doesn't have a key, the value will be null, throwing an exception when really processing should continue.

  • 🇳🇿New Zealand ericgsmith

    Yes, sorry this has been a major pain point for many.

    https://www.drupal.org/project/tamper/issues/3332785 Improve handling of empty data Active is where I tried a while ago to consolidate this but haven't had time to push it further.

    Happy for this, we probably just need to update the unit test cases as well to add one for null and ''

  • Status changed to Closed: duplicate 11 months ago
  • 🇯🇵Japan ptmkenny

    Great, I'm happy to defer to that issue!

Production build 0.71.5 2024