froala / wysiwyg-editor

The next generation Javascript WYSIWYG HTML Editor.
https://www.froala.com/wysiwyg-editor
Other
5.28k stars 673 forks source link

The "clean" parameter of "html.insert" has inverse behavior #3980

Closed earshinov closed 2 years ago

earshinov commented 4 years ago
Expected behavior

From the docs (https://froala.com/wysiwyg-editor/docs/methods/#html.insert):

clean Type: Boolean Specifies if the HTML should be cleaned prior to insertion

From this text one would conclude that passing clean=true should enable cleaning, and passing false -- disable it.

Actual behavior

It seems that true actually disables the cleaning, and false -- enables it. That is, the behavior is inverse. Below is some evidence from Froala 3.1.1 sources (js/froala_editor.min.js formatted with http://unminify.com/).

1. From the implementation of html.insert:

insert: function M(e, t, n) {
  var r;
  if (
    (w.selection.isCollapsed() || w.selection.remove(),
    // vvvvvvvvvvvvvvvvvvvvvvvvvvv
    (r = t ? e : w.clean.html(e)),
    // ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    e.indexOf('class="fr-marker"') < 0 &&
      (r = (function a(e) {
        var t = w.doc.createElement("div");
        return (t.innerHTML = e), w.selection.setAtEnd(t, !0), t.innerHTML;
      })(r)),
    w.node.isEmpty(w.el) && !w.opts.keepFormatOnDelete && f(r))
  )
    w.el.innerHTML = r;
  else {

From here you see that clean.html() is called when the second parameter (clean) is true.

2. From the implementation of paste:

function o(e, t, n) {
  // ...
      M.html.insert(e, !0);
  }
  !(function A() {
    M.events.trigger("paste.after");
  })(),
  // ...
}

By the time this code runs the inserted content (e) has already been cleaned, and according to the docs one should pass false in the second argument to disable additional cleaning inside html.insert , but actually !0 (true) is passed.

Steps to reproduce the problem
  1. Look at the docs for html.insert: https://froala.com/wysiwyg-editor/docs/methods/#html.insert
  2. Look at the code (I believe that you, unlike me, even have access to the original non-minified sources ;-))
Editor version

Froala version 3.1.1

earshinov commented 4 years ago

Related: https://github.com/froala/wysiwyg-editor/issues/1450

earshinov commented 2 years ago

I think this issue should be closed as done as well as #1450