RESOLVED FIXED 56439
Get rid of nearestMailBlockquote
https://bugs.webkit.org/show_bug.cgi?id=56439
Summary Get rid of nearestMailBlockquote
Ryosuke Niwa
Reported 2011-03-15 18:28:18 PDT
nearestMailBlockquote doesn't respect editing boundary and takes Node* instead of Position. Both of these are unconventional and all call sites of nearestMailBlockquote should be calling enclosingNodeOfType or highestEnclosingNodeOfType instead.
Attachments
cleanup + minor crash fix (14.89 KB, patch)
2011-03-15 19:03 PDT, Ryosuke Niwa
no flags
Added a null pointer check to firstPositionInOrBeforeNode/lastPositionInOrAfterNode (15.60 KB, patch)
2011-03-16 15:16 PDT, Ryosuke Niwa
no flags
Added a null pointer check to firstPositionInOrBeforeNode/lastPositionInOrAfterNode (15.45 KB, patch)
2011-03-16 16:07 PDT, Ryosuke Niwa
tony: review+
Ryosuke Niwa
Comment 1 2011-03-15 19:03:44 PDT
Created attachment 85896 [details] cleanup + minor crash fix
Ryosuke Niwa
Comment 2 2011-03-15 19:05:52 PDT
(In reply to comment #1) > Created an attachment (id=85896) [details] > cleanup + minor crash fix I included the bug fix because this was a relatively small patch but I'll split it if other people think it's better that way.
Tony Chang
Comment 3 2011-03-16 10:48:06 PDT
Comment on attachment 85896 [details] cleanup + minor crash fix View in context: https://bugs.webkit.org/attachment.cgi?id=85896&action=review > Source/WebCore/editing/ReplaceSelectionCommand.cpp:626 > + Node* blockquoteNode = (!context || isMailPasteAsQuotationNode(context)) ? context : enclosingNodeOfType(firstPositionInNode(context), isMailBlockquote, CanCrossEditingBoundary); Nit: It took me a while to figure out why you added !context (i.e., it's ok to pass NULL to isMailPasteAsQuotationNode, but it's not OK to pass NULL to firstPositionInNode). Maybe pull this out into a helper function (it could also be used in line 559). Alternately, maybe firstPositionInNode should return a null position when passed in a NULL pointer.
Ryosuke Niwa
Comment 4 2011-03-16 12:38:03 PDT
Comment on attachment 85896 [details] cleanup + minor crash fix View in context: https://bugs.webkit.org/attachment.cgi?id=85896&action=review >> Source/WebCore/editing/ReplaceSelectionCommand.cpp:626 >> + Node* blockquoteNode = (!context || isMailPasteAsQuotationNode(context)) ? context : enclosingNodeOfType(firstPositionInNode(context), isMailBlockquote, CanCrossEditingBoundary); > > Nit: It took me a while to figure out why you added !context (i.e., it's ok to pass NULL to isMailPasteAsQuotationNode, but it's not OK to pass NULL to firstPositionInNode). Maybe pull this out into a helper function (it could also be used in line 559). Alternately, maybe firstPositionInNode should return a null position when passed in a NULL pointer. Extracting a helper function sounds good. isMailPasteAsQuotationOrMailBlockquoteDescendent?
Tony Chang
Comment 5 2011-03-16 12:45:59 PDT
Comment on attachment 85896 [details] cleanup + minor crash fix View in context: https://bugs.webkit.org/attachment.cgi?id=85896&action=review >>> Source/WebCore/editing/ReplaceSelectionCommand.cpp:626 >>> + Node* blockquoteNode = (!context || isMailPasteAsQuotationNode(context)) ? context : enclosingNodeOfType(firstPositionInNode(context), isMailBlockquote, CanCrossEditingBoundary); >> >> Nit: It took me a while to figure out why you added !context (i.e., it's ok to pass NULL to isMailPasteAsQuotationNode, but it's not OK to pass NULL to firstPositionInNode). Maybe pull this out into a helper function (it could also be used in line 559). Alternately, maybe firstPositionInNode should return a null position when passed in a NULL pointer. > > Extracting a helper function sounds good. isMailPasteAsQuotationOrMailBlockquoteDescendent? Sure. I was actually just thinking of pulling out enclosingNodeOfType(firstPositionInNode(context), isMailBlockquote, CanCrossEditingBoundary) with a NULL check (nearestParentMailBlockquote?). But that works too.
Ryosuke Niwa
Comment 6 2011-03-16 14:53:12 PDT
On my second thought, my initial proposal doesn't work and adding a null check to firstPositionInNode/lastPositionInNode makes most sense now. Will be uploading a patch soon.
Ryosuke Niwa
Comment 7 2011-03-16 15:16:42 PDT
Created attachment 85984 [details] Added a null pointer check to firstPositionInOrBeforeNode/lastPositionInOrAfterNode
Tony Chang
Comment 8 2011-03-16 15:25:34 PDT
Comment on attachment 85984 [details] Added a null pointer check to firstPositionInOrBeforeNode/lastPositionInOrAfterNode View in context: https://bugs.webkit.org/attachment.cgi?id=85984&action=review > Source/WebCore/editing/htmlediting.h:118 > + return node && editingIgnoresContent(node) ? positionBeforeNode(node) : firstPositionInNode(node); This doesn't look right. && has precedence over ?, so if |node| is NULL, we return firstPositionInNode(NULL). That seems safe, but in lastPositionInOrAfterNode, we return lastPositionInNode(NULL), which calls lastOffsetInNode(NULL), which will try to dereference NULL.
Ryosuke Niwa
Comment 9 2011-03-16 15:33:01 PDT
Comment on attachment 85984 [details] Added a null pointer check to firstPositionInOrBeforeNode/lastPositionInOrAfterNode View in context: https://bugs.webkit.org/attachment.cgi?id=85984&action=review >> Source/WebCore/editing/htmlediting.h:118 >> + return node && editingIgnoresContent(node) ? positionBeforeNode(node) : firstPositionInNode(node); > > This doesn't look right. && has precedence over ?, so if |node| is NULL, we return firstPositionInNode(NULL). That seems safe, but in lastPositionInOrAfterNode, we return lastPositionInNode(NULL), which calls lastOffsetInNode(NULL), which will try to dereference NULL. Ah that's a good point. I should just do "!node ||"
Ryosuke Niwa
Comment 10 2011-03-16 16:07:44 PDT
Created attachment 85992 [details] Added a null pointer check to firstPositionInOrBeforeNode/lastPositionInOrAfterNode
Ryosuke Niwa
Comment 11 2011-03-16 16:48:34 PDT
Thanks for the review! Landing it now.
Ryosuke Niwa
Comment 12 2011-03-16 17:03:38 PDT
Note You need to log in before you can comment on or make changes to this bug.