-
Notifications
You must be signed in to change notification settings - Fork 40
Do not run AttributeToAttribute
downcast conversion on TextProxy
nodes
#1595
Conversation
I discussed this issue with @f1ames. The problem with this is that it works correctly, however it is easy to mess up. Basically, the situation when the crash occurs is when For that reason, I am actually for having the fix as proposed in this PR. I'd just add a Also, please make it clear in API docs that |
@scofalik Ready for another review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added two small things, other than that it is good.
* | ||
* @error conversion-attribute-to-attribute-on-text | ||
*/ | ||
log.warn( 'conversion-attribute-to-attribute-on-text: Trying to convert text node with attribute to attribute converter.' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text node's attribute
attribute-to-attribute
if ( !viewElement ) { | ||
/** | ||
* This error occurs when a {@link module:engine/model/textproxy~TextProxy text node} is to be downcasted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text node's attribute
Suggested merge commit message (convention)
Fix: Do not run
AttributeToAttribute
downcast conversion onTextProxy
nodes. Closes ckeditor/ckeditor5#4440.Additional information
I wanted to elaborate a little on this fix, because it looks like "Here we got a
null
exception, lets add anif
, easy-peasy, done". But it is a little more complex:The cause of this issue is described in https://github.com/ckeditor/ckeditor5-engine/issues/1587#issuecomment-441062367 - in short attribute to attribute downcast conversion is run for model
TextProxy
which is downcasted to a viewText
node which cannot have attributes directly (but converter assumes it can).The reasonable approach will be to downcast (via attribute to attribute converters) only model elements which can have attributes. However, in the model,
TextProxy
is the element which allows attributes. So checking model element for attributes acceptance doesn't make sense. Also model doesn't have a direct knowledge to what view element the model element will be downcasted to (that is the responsibility of converters). So basically to check if element can be processed by attribute to attribute conversion, view element should be checked. And this is what exactly happens here. SinceconversionApi.mapper.toViewElement( data.item )
is the first place where to be converted model element is mapped to view, it is also a proper place to check if element directly accepts attributes. In the view allElement
nodes can have attributes and other types cannot (so basicallyText
andTextProxy
). So any node different thanElement
should not be converted and sinceconversionApi.mapper.toViewElement()
method works only onElement
nodes, it returnsnull
for other elements.