I am experiencing an issue where HTML entities (such as `&` being converted to `&`) are being re-encoded each time the content is edited with the live edit. This issue occurs when a text field is edited and then reloaded. Each time I click into the field to edit, existing entities like `&` are encoded again, resulting in `amp;`, and on subsequent edits, it becomes `&`, leading to unwanted duplication of entity encoding. I've included some screenshots.

Suggested Solution:

The issue may be related to the use of innerHTML when handling content retrieval inside the module. Switching to textContent instead of innerHTML might help resolve the unintended entity encoding, as textContent returns plain text without converting or introducing HTML entities.

For example, the current code in `js/inline-editors/basic.js`:

        field.addEventListener('click', () => {
          if (!field.hasAttribute('data-me-field-is-editable')) {
            const text = field.innerHTML;
            field.setAttribute('data-me-field-is-editable', 'true');

            makeContentEditable(element, text);
          }
        });

could be switched to:

        field.addEventListener('click', () => {
          if (!field.hasAttribute('data-me-field-is-editable')) {
            const text = field.textContent;
            field.setAttribute('data-me-field-is-editable', 'true');

            makeContentEditable(element, text);
          }
        });

This change could prevent unwanted encoding.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

drupalgideon created an issue. See original summary.

nidhish’s picture

Assigned: Unassigned » nidhish

nidhish’s picture

@drupalgideon, Replacing innerhtml with textContent fixes the issue. I have created the suitable merge request for the same.

nidhish’s picture

Assigned: nidhish » Unassigned
Status: Active » Needs review

justin2pin made their first commit to this issue’s fork.

  • nidhish committed 2bc50c17 on 1.0.x
    Issue #3502573: Use textContent instead of innerHTML to prevent encoding...
justin2pin’s picture

Status: Needs review » Fixed

Looks like #5 fixes the issue. Merged, marked as fixed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.