Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x]: Argument 1 passed to craft\helpers\Html::_namespaceInputs() must be of the type string, null given #13083

Closed
birdkiwi opened this issue Apr 13, 2023 · 3 comments
Assignees

Comments

@birdkiwi
Copy link

What happened?

Description

When filling the field with a large amount of data CraftCMS returns TypeError: Argument 1 passed to craft\helpers\Html::_namespaceInputs() must be of the type string, null given, called in /app/vendor/craftcms/cms/src/helpers/Html.php on line 601

With the help of Xdebug I found out that the problem is $html variable stored as null. Null value returns because of PREG_BACKTRACK_LIMIT_ERROR inside preg_replace_callback(). pcre.backtrack_limit is "1000000" by default.

https://github.com/craftcms/cms/blob/develop/src/helpers/Html.php#L854

$markers = [];
$html = preg_replace_callback('/(<textarea\b[^>]*>)(.*?)(<\/textarea>)/is', function(array $matches) use (&$markers) {
    $marker = '{marker:' . StringHelper::randomString() . '}';
    $markers[$marker] = $matches[2];
    return $matches[1] . $marker . $matches[3];
}, $html);
return $markers;

I know that storing such a large amount of text is not a good idea, but I think that such an error should be handled in Craft to avoid customer problems.

I haven't tested it with Craft 4 yet, but looking through source I see the same issue as well.

Steps to reproduce

  1. Create a custom textarea field up to 16mb size limit
  2. Attach it to some section and fill this input in the entry. There should be more then 1 million chars in the field
  3. Try open / refresh entry in CP again

Expected behavior

CP should not throw an Exception but show an error or notification maybe? I still don't know the best way to to avoid this behavior.

Actual behavior

Internal Server error

Craft CMS version

3.8.5

PHP version

7.2.34

Operating system and version

Linux 5.15.90.1-microsoft-standard-WSL2

Database type and version

MySQL 5.7.40

Image driver and version

Imagick 3.4.4 (ImageMagick 7.0.10-48)

Installed plugins and versions

Blitz | 3.12.8
Blitz Recommendations | 1.3.0
Blitz | 3.12.8
Blitz Recommendations | 1.3.0
CP Field Inspect | 1.4.4
Groupie | 1.0.8
Incognito Field | 1.3.0
Minifier | 3.0.0
Password Policy | 1.2.0
Position Fieldtype | 1.0.17
Protected Links | 0.0.4
Redactor | 2.10.12
Sentry Logger | 1.3.1
SEOmatic | 3.4.51
SessionSync | 0.0.1
Splash | 3.0.5
Store Hours | 2.2.0
Super Table | 2.7.4
Typed link field | 1.0.25

@i-just
Copy link
Contributor

i-just commented Apr 14, 2023

Hi, thanks for reporting and for the clear reproduction steps! I raised a PR for it.

@brandonkelly
Copy link
Member

Fixed for the next Craft 3 and 4 releases via #13085

@brandonkelly
Copy link
Member

Craft 3.8.8 and 4.4.8 are out with that fix! Thanks again for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants