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

Validate position.parent's output #4531

Closed
Reinmar opened this issue Aug 7, 2019 · 3 comments · Fixed by ckeditor/ckeditor5-engine#1777
Closed

Validate position.parent's output #4531

Reinmar opened this issue Aug 7, 2019 · 3 comments · Fixed by ckeditor/ckeditor5-engine#1777
Assignees
Labels
package:engine status:discussion type:improvement This issue reports a possible enhancement of an existing feature.
Milestone

Comments

@Reinmar
Copy link
Member

Reinmar commented Aug 7, 2019

Positions and the tree to which they point are independent. It is possible to create and work with positions which point to non-existent places. This is mainly required by OT which works on a virtual states.

However, there's a set of position's properties/methods which do access the model structure. This is mainly done via reading position.parent (which is a getter) which, if the position is incorrect will either crash or return a text node. The first scenario is fairly easy to track and understand. The latter is harder because it fails later, when a text node reaches a code which expects an element.

Therefore, I propose to add validation for positions:

  • for position.parent that the returned object is really an element and not a text node,
  • (optionally) for all incorrect cases in position.parent – e.g. when you have offsets out of boundaries
  • (optionally) for other position's props/methods which don't use position.parent and may throw anyway.

cc @scofalik @pjasiun

@Reinmar Reinmar self-assigned this Aug 7, 2019
@Reinmar
Copy link
Member Author

Reinmar commented Aug 7, 2019

I'll start with the first option to check what will actually happen with our tests.

@scofalik
Copy link
Contributor

scofalik commented Aug 7, 2019

I'd go with all three. If they throw, they throw right now, so additional throwing should not change anything (except for the case when we have a silent error with a position in a text node but it worked for some reason... I wouldn't expect a lot of that, though).

@Reinmar
Copy link
Member Author

Reinmar commented Aug 7, 2019

OK, it looks very promising:

SUMMARY:
✔ 11068 tests completed
ℹ 21 tests skipped
✖ 3 tests failed

FAILED TESTS:
  MergeOperation
    _validate()
      ✖ should throw an error if source position is invalid
        Chrome 75.0.3770 (Mac OS X 10.14.4)
      AssertionError: expected [Error: FOO] to be an instance of CKEditorError

      + expected - actual


    at assertCKEditorError (webpack:///./packages/ckeditor5-utils/tests/_utils/utils.js?:137:22)
    at expectToThrowCKEditorError (webpack:///./packages/ckeditor5-utils/tests/_utils/utils.js?:115:3)
    at Context.eval (webpack:///./packages/ckeditor5-engine/tests/model/operation/mergeoperation.js?:130:114)


      ✖ should throw an error if target position is invalid
        Chrome 75.0.3770 (Mac OS X 10.14.4)
      AssertionError: expected [Error: FOO] to be an instance of CKEditorError

      + expected - actual


    at assertCKEditorError (webpack:///./packages/ckeditor5-utils/tests/_utils/utils.js?:137:22)
    at expectToThrowCKEditorError (webpack:///./packages/ckeditor5-utils/tests/_utils/utils.js?:115:3)
    at Context.eval (webpack:///./packages/ckeditor5-engine/tests/model/operation/mergeoperation.js?:164:114)


  MoveOperation
    _validate()
      ✖ should throw an error if target or source parent-element specified by position does not exist
        Chrome 75.0.3770 (Mac OS X 10.14.4)
      AssertionError: expected [Error: FOO] to be an instance of CKEditorError

      + expected - actual


    at assertCKEditorError (webpack:///./packages/ckeditor5-utils/tests/_utils/utils.js?:137:22)
    at expectToThrowCKEditorError (webpack:///./packages/ckeditor5-utils/tests/_utils/utils.js?:115:3)
    at Context.eval (webpack:///./packages/ckeditor5-engine/tests/model/operation/moveoperation.js?:181:114)

jodator referenced this issue in ckeditor/ckeditor5-engine Aug 12, 2019
Other: Position getters (such as `#parent` or `#index`) will throw when position points at an incorrect place in its root. Closes #1776.
@mlewand mlewand transferred this issue from ckeditor/ckeditor5-engine Oct 9, 2019
@mlewand mlewand added this to the iteration 26 milestone Oct 9, 2019
@mlewand mlewand added status:discussion type:improvement This issue reports a possible enhancement of an existing feature. package:engine labels Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:engine status:discussion type:improvement This issue reports a possible enhancement of an existing feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants