redactor: Error when saving Redactor fields with empty links
Description
Got a weird bug I’m seeing when saving entries sometimes.
It’s very sporadic and I can’t seem to repro on a blank project. Seems to appear when changing the contents of a Redactor field. It’s occurring when links are in Redactor fields. Craft and all plugins are up to date.
Assuming I might need to send over a copy of the DB or something.
Additional info
- Craft version: 3.7.30.1
- PHP version: PHP/7.4.16
- Database driver & version: MySql
- Plugins & versions: Blitz, Google Cloud Storage, Position Fieldtype, Redactor, SEOmatic, Super Table, Twigpack, oEmbed
Error:
TypeError: Argument 1 passed to Stringy\Stringy::startsWith() must be of the type string, null given, called in /example.com/vendor/craftcms/cms/src/helpers/StringHelper.php on line 1386 and defined in /example.com/vendor/voku/stringy/src/Stringy.php:4015
Stack trace:
#0 /example.com/vendor/craftcms/cms/src/helpers/StringHelper.php(1386): Stringy\Stringy->startsWith(NULL, true)
#1 /example.com/vendor/craftcms/redactor/src/Field.php(693): craft\helpers\StringHelper::startsWith('https://storybo...', NULL)
#2 [internal function]: craft\redactor\Field->craft\redactor\{closure}(Array)
#3 /example.com/vendor/craftcms/redactor/src/Field.php(685): preg_replace_callback('/(href=|src=)([...', Object(Closure), '<p>The site use...')
#4 /example.com/vendor/craftcms/cms/src/base/Element.php(2134): craft\redactor\Field->serializeValue('<p>The site use...', Object(craft\elements\MatrixBlock))
#5 /example.com/vendor/yiisoft/yii2/validators/InlineValidator.php(84): craft\base\Element->validateCustomFieldContentSize('caption', NULL, Object(yii\validators\InlineValidator), Object(craft\redactor\FieldData))
#6 /example.com/vendor/yiisoft/yii2/validators/Validator.php(261): yii\validators\InlineValidator->validateAttribute(Object(craft\elements\MatrixBlock), 'caption')
#7 /example.com/vendor/yiisoft/yii2/base/Model.php(367): yii\validators\Validator->validateAttributes(Object(craft\elements\MatrixBlock), Array)
#8 /example.com/vendor/craftcms/cms/src/fields/Matrix.php(799): yii\base\Model->validate()
#9 /example.com/vendor/craftcms/cms/src/base/Element.php(2107): craft\fields\Matrix->validateBlocks(Object(craft\elements\Entry), NULL)
#10 /example.com/vendor/yiisoft/yii2/validators/InlineValidator.php(84): craft\base\Element->validateCustomFieldAttribute('field:workArtic...', Array, Object(yii\validators\InlineValidator), Object(craft\elements\db\MatrixBlockQuery))
#11 /example.com/vendor/yiisoft/yii2/validators/Validator.php(261): yii\validators\InlineValidator->validateAttribute(Object(craft\elements\Entry), 'field:workArtic...')
#12 /example.com/vendor/yiisoft/yii2/base/Model.php(367): yii\validators\Validator->validateAttributes(Object(craft\elements\Entry), Array)
#13 /example.com/vendor/craftcms/cms/src/services/Elements.php(2536): yii\base\Model->validate()
#14 /example.com/vendor/craftcms/cms/src/services/Elements.php(784): craft\services\Elements->_saveElementInternal(Object(craft\elements\Entry), true, false, NULL)
#15 /example.com/vendor/craftcms/cms/src/controllers/EntriesController.php(403): craft\services\Elements->saveElement(Object(craft\elements\Entry))
#16 [internal function]: craft\controllers\EntriesController->actionSaveEntry(false)
#17 /example.com/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#18 /example.com/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#19 /example.com/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('save-entry', Array)
#20 /example.com/vendor/craftcms/cms/src/web/Application.php(287): yii\base\Module->runAction('entries/save-en...', Array)
#21 /example.com/vendor/craftcms/cms/src/web/Application.php(596): craft\web\Application->runAction('entries/save-en...', Array)
#22 /example.com/vendor/craftcms/cms/src/web/Application.php(266): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#23 /example.com/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#24 /example.com/web/index.php(22): yii\base\Application->run()
#25 {main}```
Apache/2.4.46 (Unix) mod_fastcgi/mod_fastcgi-SNAP-0910052141 PHP/7.4.16 OpenSSL/1.0.2u mod_wsgi/3.5 Python/2.7.13 Yii Framework/2.0.44```
Video of the issue failing to auto-save when a link is present:
https://user-images.githubusercontent.com/183310/152540123-2dccc4a0-ff98-404c-9e55-68aaf614e049.mp4
Redactor config:
{
"buttons": ["html", "bold", "italic", "strikethrough", "unorderedlist", "orderedlist", "link", "sup", "sub"],
"toolbarFixed": true
}
This happens across both Matrix fields using this Redactor config, and in standalone Redactor fields.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (2 by maintainers)
Commits related to this issue
- Fix craftcms/redactor#358 — committed to craftcms/html-field by brandonkelly 2 years ago
This has been fixed in
craftcms/html-field1.0.9 (for Craft 3) and 2.0.5 (for Craft 4). You can get the fix by runningcomposer update.Of course …
DEFAULT_SITE_URL="http://site.localhost"on local andDEFAULT_SITE_URL="http://www.site.come"on production. …OK.
This is caused with a bad site configuration - in this instance, when the site’s
Base URLwas not defined (once was, no idea when that got wiped!).Anyway, rubber ducking against the internet has worked! 🐤🙌