tinymce / tinymce/tinymce

Node#isEmpty considers nbsp-only node as non-empty

Open
#4,466 5 comments 0 reactions 1 assignee View on GitHub

@Afraithe is already working on this.

Since Aug 8, 2018.

status: escalated status: verified type: bug WordPress
Dominant language
TypeScript
Stars
16.3k
Forks
2.3k
PR merge metrics
No merged PRs in 30d

Description

Do you want to request a feature or report a bug?

Bug. (Or verification of intent).

What is the current behavior?

When a new block is created, it is padded with an   non-breaking space character. The behavior of Node#isEmpty disregards whitespace, but not specifically the non-breaking space character.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via fiddle.tinymce.com or similar.

Demo: http://fiddle.tinymce.com/Pugaab

Enter some content and press Enter.

More directly, it could be reproduced by a test case on creating an empty text node.

const documentNode = Node.create( '#document-fragment' );
const textNode = Node.create( '#text' );
textNode.value = String.fromCharCode( 160 );
documentNode.append( textNode );
console.log( documentNode.isEmpty() );
// false

Possible solution: If changing the regular expression to use \s instead of , isEmpty correctly returns true.

Before:

https://github.com/tinymce/tinymce/blob/7dfd8102cadfb35e7304cacec7f122aa9e81b1ad/src/core/main/ts/api/html/Node.ts#L14

After:

const whiteSpaceRegExp = /^[\s\t\r\n]*$/;

What is the expected behavior?

The logged result should show "Is empty: true" since it is for the newly-created empty paragraph.

Which versions of TinyMCE, and which browser / OS are affected by this issue? Did this work in previous versions of TinyMCE?

TinyMCE 4.7.13
Unaware of previous working state.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.