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

Consistent use of single quote entity #9211

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Jojoshua
Copy link

@Jojoshua Jojoshua commented Nov 30, 2023

Using &#39 is problematic with certain frameworks. We used to get around this using the following code in v4

setup: function (editor: Editor) {
    editor.on("SaveContent", function (i) {
      i.content = i.content.replace(/&#39/g, "&apos");
    });

However this doesn't work in v6 anymore.

@TheSpyder
Copy link
Member

The SaveContent event has a very specific use case. Try GetContent, that should work for any scenario where content is retrieved from the editor.

@Jojoshua
Copy link
Author

Jojoshua commented Dec 4, 2023

The SaveContent event has a very specific use case. Try GetContent, that should work for any scenario where content is retrieved from the editor.

The scenario is that I am triggering save on all the TinyMCe's on the page and I need this replacement to happen at that time before I post it to the server. Is GetContent going to work when save is triggered? If the single quote doesn't get converted to apos, the .net framework thinks it's being attacked.

@TheSpyder
Copy link
Member

Is GetContent going to work when save is triggered?

Yes. The event is dispatched every time getContent() is called, and the event is able to mutate the content as a string.

const processedEventArgs = withSerializedContent(content, (content) => Events.fireGetContent(editor, { ...args, content }), { sanitize: Options.shouldSanitizeXss(editor), sandbox_iframes: Options.shouldSandboxIframes(editor) });
return processedEventArgs.content;

@spocke
Copy link
Member

spocke commented Dec 19, 2023

The reason why don't use apos here is that it's not a valid HTML 4 entity. So at the time of writing that code there where browsers that didn't support the apos entity for example IE. However I failed to find out what exact IE versions doesn't support it.

Here is the entities in the HTML4 spec notice that apos is not there:
https://www.w3.org/TR/REC-html40/sgml/entities.html

However it is in this HTML5 reference:
https://html.spec.whatwg.org/multipage/named-characters.html#named-character-references

Since this is such a central thing and the HTML that the editor generates could in theory be still be displayed on old IE based HTML renderers I'm not confident that we can just change this without having some form of option to configure it back to the old IE legacy mode.

@Jojoshua
Copy link
Author

I figured it was an IE thing. I will try a flag.

@spocke
Copy link
Member

spocke commented Dec 19, 2023

Curious what dotnet sanitization framework requires apos over numeric entities? Want to see if I can reproduce the issue and estimate how common this problem is.

@Jojoshua
Copy link
Author

Curious what dotnet sanitization framework requires apos over numeric entities? Want to see if I can reproduce the issue and estimate how common this problem is.

In my scenario it is ASP.NET MVC. If you google search something like tinymce single quote .net you can find posts of the issue.

To reproduce just set tinymce option encoding: 'xml' then try to post it to the server.

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

Successfully merging this pull request may close these issues.

None yet

3 participants