[webkit-changes] [WebKit/WebKit] 71e39c: When converting HTML that contains an image to an ...

Richard Robinson noreply at github.com
Tue May 28 20:43:01 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 71e39c7bd8fc08ef9171cf4bfbaed96673158980
      https://github.com/WebKit/WebKit/commit/71e39c7bd8fc08ef9171cf4bfbaed96673158980
  Author: Richard Robinson <richard_robinson2 at apple.com>
  Date:   2024-05-28 (Tue, 28 May 2024)

  Changed paths:
    M Source/WebCore/editing/cocoa/HTMLConverter.mm
    M Source/WebCore/loader/mac/LoaderNSURLExtras.h
    M Source/WebCore/loader/mac/LoaderNSURLExtras.mm

  Log Message:
  -----------
  When converting HTML that contains an image to an attributed string and back using `HTMLConverter::editingAttributedString`, the image is lost
https://bugs.webkit.org/show_bug.cgi?id=274701
rdar://128717614

Reviewed by Aditya Keerthi.

When converting an NSAttributedString to an HTML document fragment, if the attributed string
contains a text attachment backed by a file wrapper without a preferred file name, the attachment
is dropped and not converted to HTML.

Fix by ensuring that a file wrapper for an image always has a preferred file name when converting
HTML to an attributed string inside of `HTMLConverter::editingAttributedString` using the following
mechanism:

1. If the image is backed by an attachment, use the attachment's title as the preferred name.
2. Otherwise, try to use the image's alt attribute's value as the preferred name, if present.
3. Otherwise, try to convert the image's url into a filename and use that as the preferred name.
4. If all else fails, use the default "unknown" file name as the preferred name.

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

Canonical link: https://commits.webkit.org/279425@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