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

Inline font-size style using absolute sizes (small, medium, large etc) throws error. setContents() fails #1207

Closed
andylwelch opened this issue Apr 3, 2023 · 1 comment
Labels
Milestone

Comments

@andylwelch
Copy link
Contributor

Describe the bug
Rendering html with an inline style that has a font-size as a word (e.g. small) throws an error which crashes the editor completely in my page.

To Reproduce
Steps to reproduce the behavior:

  1. Go to http://suneditor.com/sample/index.html
  2. Click on Code view button
  3. Paste html in editor:
    <p><span style='font-size: small;'>Test</span></p>
  4. Open browser console, see error:
Uncaught TypeError: Cannot read properties of null (reading '1')
    at Object._cleanStyle (core.js:5277:96)
    at Object._cleanTags (core.js:5335:34)
    at String.replace (<anonymous>)
    at Object.cleanHTML (core.js:5460:111)
    at Object.getContents (core.js:5114:35)
    at h (history.js:56:30)
    at Object.push (history.js:114:21)
    at Object.toggleCodeView (core.js:4685:34)
    at Object.commandHandler (core.js:4515:26)
    at Object.actionCall (core.js:4464:22)

Uncaught TypeError: Cannot read properties of null (reading '1')
    at Object._convertFontSize (core.js:5224:29)
    at Object.active (fontSize.js:66:89)
    at Object._applyTagEffects (core.js:6394:90)
    at HTMLDivElement.onClick_wysiwyg (core.js:6581:23)

Expected behavior
HTML with valid font-size style attribute should render without crashing.

Screenshots
image
Crash:
image
image

On Suneditor.com
image

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Chrome
  • Version: 111.0.5563.147

Additional context
Looking at the code, the bug is only if fontSize plugin is utilised. Possibly a mistmatch in the regex used for testing and the regex used for matching/replacing:

...
if (!this._cleanStyleRegExp.fontSizeUnit.test(r[0])) {
        r[0] = r[0].replace(this._w.RegExp('\\d+' + r[0].match(/\d+(.+$)/)[1]), this._convertFontSize.bind(this, options.fontSizeUnit));
}
...
@andylwelch andylwelch changed the title Inline font-size style using absolute sizes (small, medium, large etc) crashes editor Inline font-size style using absolute sizes (small, medium, large etc) throws error. setContents() fails Apr 3, 2023
@JiHong88 JiHong88 added the bug label Apr 3, 2023
@JiHong88 JiHong88 added this to the 2.44.7 milestone Apr 3, 2023
JiHong88 added a commit that referenced this issue Apr 7, 2023
@JiHong88 JiHong88 closed this as completed Apr 7, 2023
@JiHong88
Copy link
Owner

JiHong88 commented Apr 9, 2023

The 2.44.7 version has been updated.
Thank you.

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

2 participants