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

[GHS] Editor crashes after inserting nested inline element with a class #10657

Closed
Mgsy opened this issue Oct 7, 2021 · 8 comments · Fixed by #11488
Closed

[GHS] Editor crashes after inserting nested inline element with a class #10657

Mgsy opened this issue Oct 7, 2021 · 8 comments · Fixed by #11488
Assignees
Labels
package:html-support squad:core Issue to be handled by the Core team. support:2 An issue reported by a commercially licensed client. type:bug This issue reports a buggy (incorrect) behavior.

Comments

@Mgsy
Copy link
Member

Mgsy commented Oct 7, 2021

📝 Provide detailed reproduction steps (if any)

  1. Go to https://ckeditor.com/docs/ckeditor5/latest/features/general-html-support.html.
  2. Insert the following content to the editor (via source editing):
<span>
    <span class="test">test</span>
</span>

✔️ Expected result

The content inserts properly.

❌ Actual result

The editor crashes.

📃 Other details

The issue occurs only if the parent element is the same element as the nested one and the nested one contains a class.

Error

emittermixin.js:232 Uncaught TypeError: target[key] is not iterable
    at mergeViewElementAttributes (conversionutils.js:48)
    at UpcastDispatcher.dispatcher.on.priority (converters.js:104)
    at UpcastDispatcher.fire (emittermixin.js:199)
    at UpcastDispatcher._convertItem (upcastdispatcher.js:249)
    at UpcastDispatcher._convertChildren (upcastdispatcher.js:282)
    at UpcastDispatcher.<anonymous> (upcasthelpers.js:439)
    at UpcastDispatcher.fire (emittermixin.js:199)
    at UpcastDispatcher._convertItem (upcastdispatcher.js:253)
    at UpcastDispatcher.convert (upcastdispatcher.js:207)
    at datacontroller.js:437

If you'd like to see this fixed sooner, add a 👍 reaction to this post.

@shabab477
Copy link

Anyone working on this fix?

@shabab477
Copy link

Hi, we have some mission-critical content that can't be dropped in order to get through this bug. Is a PR welcome to fix this?

@theezeb

This comment has been minimized.

@shabab477
Copy link

shabab477 commented Dec 7, 2021

@shahzebgit easiest fix should be just to do this at the source:

export function mergeViewElementAttributes( target, source ) {
	const result = cloneDeep( target );

	for ( const key in source ) {

		// Merge classes.
		if ( !Array.isArray( target[ key ] ) ) {
			continue;
		} 
		
		else if ( Array.isArray( source[ key ] ) ) {
			result[ key ] = Array.from( new Set( [ ...target[ key ], ...source[ key ] ] ) );
		}

		// Merge attributes or styles.
		else {
			result[ key ] = { ...target[ key ], ...source[ key ] };
		}
	}

	return result;
}

Any suggestion for a better fix? Looking to hear from the project maintainers too. @Mgsy

@theezeb
Copy link

theezeb commented Dec 7, 2021

@shabab477 yeah even i'm using something similar solution for now, but i think better solution would be to preserve the class even if it doesn't finds target classes to merge here.

if ( !Array.isArray( target[ key ] ) ) {
continue;
}

this here helps us to avoid the error for mean time.

I made little change for this, this helps it to let the classes get applied even if it doesn't have anything to merge with.

if (!Array.isArray(target[key])) {
result[key] = source[key];
}

@shabab477
Copy link

Yeah, this looks better, right now I am building from source and deploying in our app but would be great to have it in the upstream.

@theezeb
Copy link

theezeb commented Dec 7, 2021

Made a bit more changes hope this solves the issue here.

Here isEmpty method would really help to check if the target is empty(Obj) or not instead of checking for undefined.
will make changes if needed.

export function mergeViewElementAttributes( target, source ) {
	const result = cloneDeep( target );

	for ( const key in source ) {
		//If target is empty, just copy the source.
		if (target[key] === undefined)) {
			result[key] = source[key];
		}
		// Merge classes.
		else if ( Array.isArray( source[ key ] ) ) {
			result[ key ] = Array.from( new Set( [ ...target[ key ], ...source[ key ] ] ) );
		}

		// Merge attributes or styles.
		else {
			result[ key ] = { ...target[ key ], ...source[ key ] };
		}
	}

	return result;
}

@Reinmar
Copy link
Member

Reinmar commented Mar 17, 2022

We'll be working soon on a bug that throws the same error (#11450) so hopefully this issue will be resolved too.

@arkflpc arkflpc self-assigned this Mar 18, 2022
@CKEditorBot CKEditorBot added the status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. label Mar 18, 2022
dawidurbanski added a commit that referenced this issue Mar 21, 2022
…tributes

Fix (html-support): Prevent `TypeError` in `mergeViewElementAttributes`. Closes #10657. Closes #11450. Closes #11477.
@CKEditorBot CKEditorBot removed the status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. label Mar 21, 2022
@CKEditorBot CKEditorBot added this to the iteration 52 milestone Mar 21, 2022
@martynawierzbicka martynawierzbicka added the support:2 An issue reported by a commercially licensed client. label Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:html-support squad:core Issue to be handled by the Core team. support:2 An issue reported by a commercially licensed client. type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants