aimeos / ai-admin-jqadm

Aimeos e-commerce Vue.js+Bootstrap based admin interface
https://aimeos.org
GNU Lesser General Public License v3.0
182 stars 43 forks source link

html editor not detecting content on copy/paste from external sources such as MS Word #231

Closed jgautrais closed 2 years ago

jgautrais commented 2 years ago

Environment

  1. Version 2021.10
  2. Integration Laravel 8.68.1
  3. Docker with php 7.4

Describe the bug The html editor does not recognize content when copy/pasting from MS Word. We noticed this bug in production. This is due to content from MS Word having a specific class attribute: aimeos-htmleditor-msword The console is throwing the following error:

Uncaught TypeError: Cannot read properties of null (reading 'length')

The code throwing the error is the following (in ai-admin-jqadm/js/components/html-editor.js, line 50):

if(this.content.match(/<p>/g).length === 1 && this.content.startsWith('<p>') && this.content.endsWith('</p>')) {
    ...
}

The regex /<p>/g tested in the match function does not handle p tag having a class attribute and the match function is returning null if no matches are found (doc). Therefore this.content.match(/<p>/g).length is throwing an error.

Proposed solution Locally we can solve the issue by checking first that this.content.match(/<p>/g) is thruthy

AurelGit commented 2 years ago

Same trouble, if no <p> tag exists, it will raise an error and the editor do not consider that the text is modified.

aimeos commented 2 years ago

Fixed in dev-master 2022.04.x-dev and 2021.10.x-dev. New versions will be tagged this week.