[Webkit-unassigned] [Bug 187212] [macOS] Don't treat URL titles as URLs when adding to the pasteboard

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sun Jul 1 14:33:15 PDT 2018


https://bugs.webkit.org/show_bug.cgi?id=187212

Darin Adler <darin at apple.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |darin at apple.com

--- Comment #14 from Darin Adler <darin at apple.com> ---
Comment on attachment 344043
  --> https://bugs.webkit.org/attachment.cgi?id=344043
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=344043&action=review

> Source/WebCore/platform/mac/PlatformPasteboardMac.mm:311
> +    RetainPtr<NSMutableArray> paths = adoptNS([[NSMutableArray alloc] init]);
> +    NSURL *cocoaURL = pasteboardURL.url;
> +    [paths.get() addObject:[NSArray arrayWithObject:[cocoaURL absoluteString]]];
> +    [paths.get() addObject:[NSArray arrayWithObject:pasteboardURL.title]];

Here’s a way to write this with array literals:

    NSURL *cocoaURL = pasteboardURL.url;
    NSArray *paths = @[ @[ cocoaURL.absoluteString ], @[ pasteboardURL.title ] ];

This has advantages like not creating a mutable array, sizing the array better, and being two lines of code instead of four, but a tiny disadvantage of doing one more autorelease.

> Source/WebCore/platform/mac/PlatformPasteboardMac.mm:313
> +    NSString *pasteboardType  = [NSString stringWithFormat:@"%s", WebURLsWithTitlesPboardType];

This should be one of these instead:

    NSString *pasteboardType = [NSString stringWithCString:WebURLsWithTitlesPboardType encoding:NSASCIIStringEncoding];
    NSString *pasteboardType = [NSString stringWithUTF8String:WebURLsWithTitlesPboardType];

Using the formatting version instead is less efficient. I also think it’s a bit peculiar that we have constants named WebURLsWithTitlesPboardType in both WebCore and WebKit, but in WebCore it’s a C string whereas in WebKit it’s an NSString. Might be nice to get rid of that pattern some day. If this was already an NSString it would be better for this call site, but I presume it would be worse for other call sites.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20180701/a7794d74/attachment.html>


More information about the webkit-unassigned mailing list