[webkit-changes] [WebKit/WebKit] 41bef3: [WritingTools] ObjC exception in `preferredFilenam...

Wenson Hsieh noreply at github.com
Thu Feb 27 20:47:07 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 41bef39eadb8d5a1a4c4f79eaa39834997d8d2e2
      https://github.com/WebKit/WebKit/commit/41bef39eadb8d5a1a4c4f79eaa39834997d8d2e2
  Author: Wenson Hsieh <wenson_hsieh at apple.com>
  Date:   2025-02-27 (Thu, 27 Feb 2025)

  Changed paths:
    M Source/WebCore/editing/cocoa/HTMLConverter.mm
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/WritingTools.mm

  Log Message:
  -----------
  [WritingTools] ObjC exception in `preferredFilenameForElement` under `-[NSFileWrapper setPreferredFilename:]`
https://bugs.webkit.org/show_bug.cgi?id=288771
rdar://145408164

Reviewed by Aditya Keerthi and Abrar Rahman Protyasha.

Make `fileWrapperForElement(const HTMLImageElement&)` robust in the case where the image element is
backed by an attachment element without a `title` attribute. Currently, our logic to extract the
`preferredFilenameForElement` does the following:

```
if (RefPtr attachmentElement = element.attachmentElement())
    return attachmentElement->attachmentTitle();
```

...which causes us to pass an empty string as the `NSFileWrapper`'s preferred file name, which in
turn causess an ObjC exception to be thrown. We can instead make this more robust, by only returning
the attachment element's title if it's non-empty.

* Source/WebCore/editing/cocoa/HTMLConverter.mm:
(preferredFilenameForElement):

See above. Additionally rearrange this helper, to guarantee that we *always* return a non-empty
string by guarding every early return with an `!….isEmpty()` check. The fallback return value,
`copyImageUnknownFileLabel()`, just looks up a hard-coded fallback string from the localized strings
dictionary, so it should always exist.

* Tools/TestWebKitAPI/Tests/WebKitCocoa/WritingTools.mm:
(TEST(WritingTools, ProofreadingWithUntitledImageAttachment)):

Add a new API test to exercise this crash fix.

Canonical link: https://commits.webkit.org/291293@main



To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications


More information about the webkit-changes mailing list