JSON is null from convertLegacyTags

Created on 13 March 2023, over 1 year ago
Updated 20 November 2023, 12 months ago

Problem/Motivation

Some of our site editors have encountered an issue where they insert a view and by some process the view element in the source HTML is getting an "inserted_view_adv" attribute attached to it. This attribute causes the convertLegacyTags function to run, but returns no matches in the regular expression search. This causes the value of the "json" variable to be set to null and causes the editor to crash when loading the page. I am not sure what process the editors are using to get this odd legacy code, but I can confirm that the presence of the code causes the CKEditor plugin (and corresponding editor) to crash.

Steps to reproduce

  1. Create a view and insert it with a basic setup, something along the lines of:
    <drupal-view data-arguments="" data-display-id="block_1" data-view-id="test_view"></drupal-view>
  2. Edit this view to include a legacy "inserted_view_adv" attribute like so:

    <drupal-view data-arguments="" data-display-id="block_1" data-view-id="test_view" inserted_view_adv="test_view=block_1"></drupal-view>

  3. Save the page.
  4. Try to Edit the page again

Proposed resolution

Based on the documentation for the String.matches() function, it will return NULL when no matches are found. Adding a check to ensure that the json variable is set/not null to the conditional right after it is assigned will ensure that if no matches are found it will move on without failing. This should make the plugin more robust against these potentially malformed insert tokens. I've attached a patch that safeguards this function against this issue.

Remaining tasks

There still is the unresolved issue of where this attribute is getting added to inserted tokens. There is a chance these may be getting copied from some pre-existing legacy tokens, but our editors claim this has occurred merely by inserting the tags on a page.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States pkozik

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

Comments & Activities

Production build 0.71.5 2024