Skip to content

Commit

Permalink
[iOS] Use default scheme for copied URLs without schemes
Browse files Browse the repository at this point in the history
The iOS async clipboard APIs |detectPatternsForPatterns:| and
|detectValuesForPatterns:| return YES and a value even if the copied
data is a text url with no scheme. In this case, default to https when
constructing a URL/GURL.

Bug: 1306773
Change-Id: I649fa194a10a2ffc945335ba01d397744a3d2690
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3540620
Reviewed-by: Olivier Robin <[email protected]>
Commit-Queue: Robbie Gibson <[email protected]>
Cr-Commit-Position: refs/heads/main@{#983451}
  • Loading branch information
rkgibson2 authored and Chromium LUCI CQ committed Mar 21, 2022
1 parent 527964a commit 5ba92b2
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
// Key used to store the last date at which it was detected that the pasteboard
// changed. It is used to evaluate the age of the pasteboard's content.
NSString* const kPasteboardChangeDateKey = @"PasteboardChangeDate";
// Default Scheme to use for urls with no scheme.
NSString* const kDefaultScheme = @"https";

} // namespace

Expand Down Expand Up @@ -392,6 +394,16 @@ - (void)recentURLFromClipboardAsync:(void (^)(NSURL*))callback {
URLWithString:
values[UIPasteboardDetectionPatternProbableWebURL]];

// |detectValuesForPatterns:| will return a url even if the url
// is missing a scheme. In this case, default to https.
if (url.scheme == nil) {
NSURLComponents* components =
[[NSURLComponents alloc] initWithURL:url
resolvingAgainstBaseURL:NO];
components.scheme = kDefaultScheme;
url = components.URL;
}

if (![self.authorizedSchemes containsObject:url.scheme]) {
weakSelf.cachedURL = nil;
callback(nil);
Expand Down

0 comments on commit 5ba92b2

Please sign in to comment.