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

Fix off-by-one in deleteCell and deleteRow index checks #1890

Merged
merged 1 commit into from
Oct 18, 2016

Conversation

foolip
Copy link
Member

@foolip foolip commented Oct 12, 2016

This was likely copied from insertCell, where it makes sense.

Discovered when reviewing an implementation change:
https://codereview.chromium.org/2406423004/

@foolip
Copy link
Member Author

foolip commented Oct 12, 2016

This already has test coverage in https://github.com/w3c/web-platform-tests/blob/master/html/semantics/tabular-data/the-tr-element/deleteCell.html ("HTMLTableRowElement deleteCell(cells.length)")

Copy link

@rwlbuis rwlbuis left a comment

Choose a reason for hiding this comment

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

Looks good, I noticed deleteRow has the same wording.

@foolip
Copy link
Member Author

foolip commented Oct 12, 2016

To be clear, deleteRow already says "greater than or equal to" and doesn't need changing, right?

<p>If the given position is less than &#x2212;1 or greater than the index of the last cell, or
if there are no cells, throws an <span>"<code>IndexSizeError</code>"</span>
<p>If the given position is less than &#x2212;1 or greater than or equal to the index of the
last cell, or if there are no cells, throws an <span>"<code>IndexSizeError</code>"</span>
Copy link

Choose a reason for hiding this comment

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

Actually I think this part of the change is wrong. If there is only one cell, last cell index will be 0 and deleteCell(0) should be safe to do.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, I'll align the wording with the below. Can I ack you as "Rob Buis"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, two other dom intro blocks share the "index of the last x" wording, so I'll just keep it.

<li><p>If <var>index</var> is less than &#x2212;1 or greater than the number of elements in
the <code data-x="dom-tr-cells">cells</code> collection, then throw an
<li><p>If <var>index</var> is less than &#x2212;1 or greater than or equal to the number of
elements in the <code data-x="dom-tr-cells">cells</code> collection, then throw an
Copy link

Choose a reason for hiding this comment

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

This still seems correct, if there is 1 cell, index equal to number of elements is 1, and deleteCell(1) should be "out of range".

Copy link

Choose a reason for hiding this comment

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

Ok new wording is fine.

@rwlbuis
Copy link

rwlbuis commented Oct 12, 2016

https://html.spec.whatwg.org/#dom-tbody-deleterow seems to have the same problem:
If index is less than −1 or greater than the number of elements in the rows collection, then throw an "IndexSizeError" DOMException.

@domenic domenic added the do not merge yet Pull request must not be merged per rationale in comment label Oct 18, 2016
@foolip
Copy link
Member Author

foolip commented Oct 18, 2016

Sorry @rwlbuis, I didn't see your comments 6 days ago, must have accidentally marked some mail as read.

@foolip
Copy link
Member Author

foolip commented Oct 18, 2016

Well this is interesting, per current spec table.deleteRow(-1) should throw while tbody.deleteRow(-1) should should do nothing in the case where there are no rows. Needs testing!

@foolip
Copy link
Member Author

foolip commented Oct 18, 2016

Per the testing in web-platform-tests/wpt#4001 I think the best outcome is for table.deleteRow(-1) to also not throw, making it consistent with the others. Three engines will have to change, but it's the less risky change, and makes things more consistent. I'll do it in a separate PR though.

This was likely copied from insertCell, where it makes sense.

Discovered when reviewing an implementation change:
https://codereview.chromium.org/2406423004/
@foolip foolip changed the title Fix off-by-one in deleteCell's index check Fix off-by-one in deleteCell and deleteRow index checks Oct 18, 2016
@foolip
Copy link
Member Author

foolip commented Oct 18, 2016

That's #1924

@foolip foolip removed the do not merge yet Pull request must not be merged per rationale in comment label Oct 18, 2016
@foolip
Copy link
Member Author

foolip commented Oct 18, 2016

Still no new tests required for this, the three files touched by web-platform-tests/wpt#4001 have tests in the style of "HTMLTableRowElement deleteCell(cells.length)" for all three cases.

@foolip
Copy link
Member Author

foolip commented Oct 18, 2016

@zcorpan care to review?

@@ -120102,6 +120102,7 @@ INSERT INTERFACES HERE
Rikkert Koppes,
Rimantas Liubertas,
Riona Macnamara,
Rob Buis,
Copy link

Choose a reason for hiding this comment

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

Thanks for adding me :)

@foolip
Copy link
Member Author

foolip commented Oct 18, 2016

Thanks @rwlbuis, I'll take that as review and am merging now.

@foolip foolip merged commit 43e7a55 into master Oct 18, 2016
@foolip foolip deleted the deleteCell-off-by-one branch October 18, 2016 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants