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

Changing list type wont throw error for empty list elements #2440

Merged
merged 19 commits into from
Jan 3, 2019
Merged

Conversation

msamsel
Copy link
Contributor

@msamsel msamsel commented Sep 26, 2018

What is the purpose of this pull request?

Bug fix

Does your PR contain necessary tests?

All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.

This PR contains

  • Unit tests
  • Manual tests

What changes did you make?

  • Fix throwing errors in console, when markup with empty ul list was changed to different list type.

Close #2411

Related also to #2438

@mlewand mlewand self-requested a review September 28, 2018 06:33
@mlewand mlewand self-assigned this Sep 28, 2018
Copy link
Contributor

@mlewand mlewand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checks in your patch are bit too loose, you can still get the error which is a subject of this issue by following a manual test but putting following markup as input:

<ul>
	<li>
		<div>test<ul>
				<!-- I'm a sneaky little comment -->
			</ul>
		</div>
	</li>
	<li>test</li>
</ul>

Good job with covering existing functionality (that has not been covered with unit tests yet).

@@ -0,0 +1,30 @@
<h2>Markup 1:</h2>
<input type="text" value="&lt;ul&gt;&lt;li&gt;&lt;div&gt;test&lt;ul&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;test&lt;/li&gt;&lt;/ul&gt;">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be helpful to mark these inputs as readonly.


## Expected:
There is no error in console.
However content might look strange and this is not a bug, situation is reportd as list plugin improvement.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reportd

-> reported

Actually it would be nice to link mentioned issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might look strange and this is not a bug

This actually is a buggy content, but it is to be fixed in mentioned issue 😕

</ul>

<ul>
<li><a href="https://powerusers.microsoft.com/plugins/common/feature/oauth2sso/sso_login_redirect?referer=https%3A%2F%2Fpowerusers.microsoft.com%2Ft5%2FPowerApps-Community%2Fct-p%2FPowerApps1">Register</a></li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use dummy links.

function isEmptyList( groupObj ) {
// If list is without any li item, then ignore such element from transformation, becasue it throws errors in console.
// Hack for situation described in #2411, #2438.
return groupObj.root.is( 'ul', 'ol' ) && groupObj.root.getChildCount() === 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse listNodeNames to identify list tag names.

Actually in my opinion we should use DTD here (CKEDITOR.dtd.$list) but for some reason it was skipped. Maybe because it should handle only lists, and not description list.


var tests = {
'test conversion of embedded unordered list and paragraphs to numbered list': function( editor, bot ) { // Strange test result for: 0, 8
var testesLength = 9;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subsequent var declarations/initialization should be contained within a single var statement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue appears later on, please correct each occurence.

@@ -0,0 +1,468 @@
<!--

Strange output markup for tests:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid information duplication. You have already provided this info in blockconversion.js.

blockconversion.js is where the logic of tests are so it is the best place to put this information. Here it's not needed, as it is only a resource file for the logic.

};

var tests = {
'test conversion of embedded unordered list and paragraphs to numbered list': function( editor, bot ) { // Strange test result for: 0, 8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange test result for: 0, 8 comment will look much better in a line below. Here it exceeds 120 chars which, if convenient, we like to avoid.

@msamsel msamsel self-assigned this Oct 1, 2018
@msamsel msamsel force-pushed the t/2411 branch 2 times, most recently from 84284d2 to 59d2ff2 Compare December 11, 2018 08:53
@msamsel msamsel removed their assignment Dec 11, 2018
@msamsel msamsel requested a review from mlewand December 11, 2018 08:58
@mlewand mlewand self-assigned this Jan 3, 2019
@mlewand
Copy link
Contributor

mlewand commented Jan 3, 2019

I have rebased the branch (resolved conflict in CHANGES.md). Also I've adjusted manual test description.

Copy link
Contributor

@mlewand mlewand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

childCountWithoutComments method is a blocker for this fix

core/tools.js Outdated
* @param {CKEDITOR.dom.element} node Element whos children will be counted.
* @returns {Number} Amount of node's children without counting comments.
*/
childCountWithoutComments: function( node ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't add a method like that, it doesn't belong here.

  1. Logically it belongs to CKEDITOR.dom.element type - this is where it should be added.
  2. It's too specific to your particular use case. Having a method like that would be excuse for getChildCountWithoutNodes, getChildCountWithoutElements etc. Instead getChildCount method should be modified to accept options param, that allows to specify options.exclude or options.include. So you'd call it like elem.getChildCount( { exclude: [ CKEDITOR.NODE_COMMENT ] } );.
  3. Name is not aligned with existing getChildCount method.

Finally there's a minor naming issue, node can not have children so the arg should be called element just like you described in @param's description.

I should have pointed this out in previous review.

@mlewand
Copy link
Contributor

mlewand commented Jan 3, 2019

I have fixed the issue that I raised during the review by simply inlining the function. Ideally I'd like CKEDITOR.dom.element methods to get include / exclude options, but that would mean that this fix would need to wait for the major release.

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

Successfully merging this pull request may close these issues.

2 participants