Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OutputData is wrongly manipulated and does not match expected output #1072

Open
natterstefan opened this issue Mar 20, 2020 · 11 comments
Open
Labels

Comments

@natterstefan
Copy link
Contributor

natterstefan commented Mar 20, 2020

Current Setup

Documented and prepared in this codesandbox example.

Note: It doesn't matter if this is tested with or without react (I've prepared both, see links below)

Current Setup

Let's assume I've a the following data object:

export const data = {
  blocks: [
    {
      type: 'header',
      data: {
        text: 'Editor.js',
        level: 2,
      },
    },
    {
      type: 'react',
      data: {
        url: 'remote.adjust.rotate=0&remote.size.w=5575&remote.size.h=3717',
      },
    },
  ],
}

When passing this later on to EditorJS everything works fine (note: tested in a react setup, but it does not really matter if it's plain js or not).

Current Problem

When I now get the data from the editor with await editor.save() the data is corrupt and looks like this:

	{
      type: 'react',
      data: {
        url: 'remote.adjust.rotate=0&remote.size.w=5575&remote.size.h=3717',
      },
    },

remote.adjust.rotate=0& vs. remote.adjust.rotate=0&remote... :/

This only happens since @editorjs/[email protected] in the latest 2.16 release everything works still (see codesandbox with 2.16.1).

Example Apps

@gohabereg
Copy link
Member

Hi @natterstefan
Thanks for the report! It seems we need to escape entities after saving as html-janitor inserts data to temp DOM nodes on sanitizing

@natterstefan
Copy link
Contributor Author

Hi and you're welcome @gohabereg.

Do you think this can be resolved pretty easily and quickly or is this something big?

@gohabereg
Copy link
Member

Should not be too big, I will provide some details later

@natterstefan
Copy link
Contributor Author

Thank you very much @gohabereg.

@gohabereg
Copy link
Member

Hi @natterstefan

Thanks for the reminder :)

A method that sanitizes blocks after save called is here — https://github.com/codex-team/editor.js/blob/master/src/components/modules/sanitizer.ts#L59

As you can see, if there is no sanitize config of any kind, it returns data as it is. But the problem is there is always sanitize config for inline-tools as this method appends br and wbr tags (2.17 changes).

The solution is actually simple — if a tool doesn't provide inlineToolbar option, return an empty object from getInlineToolsConfig.

The second step would be to decode HTML entities after sanitize, but as we include inline tags to Editor's output, it would break the markup

@natterstefan
Copy link
Contributor Author

natterstefan commented Mar 27, 2020

Hi @gohabereg,

Okay, sounds doable. Is this a topic you gonna fix in editorjs itself, or is this something a user of the lib must fix individually?

Would you mind updating the attached codepen and show me how one would solve it, please? Both steps (getInlineToolsConfig and decode HTML entities after sanitize) are required, right?

@gohabereg
Copy link
Member

Hi @natterstefan,

It should be fixed in the editor itself

@neSpecc neSpecc added the bug label Apr 11, 2020
@MohitKS5
Copy link

MohitKS5 commented May 18, 2020

Any update or workaround on this ?
@natterstefan were you able to find something?

@thomas-obernberger
Copy link

is there any update on this?

@orbachar
Copy link

any update? is there a workaround?

@kguelzau
Copy link

I tried to understand the problem.

The behavior changed with #1016. As @gohabereg said, this triggers the sanitizer even when there is no sanitizer config .
The sanitizer uses innerHTML to do the job, which is totally fine for html data.
some text <a href="https://host/?a=1&b=2">and a link</a>
...will sanitized to...
some text <a href="https://host/?a=1&amp;b=2">and a link</a>

Actually I don't think this is really a bug.
When a block tool wants to provide non html data on save, it has to sanitize the data manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants