Skip to content

Commit

Permalink
REGRESSION(267111@main): Safari crash when tapping “allow for one day…
Browse files Browse the repository at this point in the history
…” Terminating app due to uncaught exception.

https://webkit.org/b/260828
rdar://114581149

Reviewed by Chris Dumez.

The matchesURL: and matchesURL:options: methods should take nil for the URL and always return NO.
This was happening by accident before. Also mark the match methods as taking nullable URLs and patterns.

* Source/WebKit/UIProcess/API/Cocoa/_WKWebExtensionMatchPattern.h:
* Source/WebKit/UIProcess/API/Cocoa/_WKWebExtensionMatchPattern.mm:
(-[_WKWebExtensionMatchPattern matchesURL:options:]): Return early if the URL is nil.

Canonical link: https://commits.webkit.org/267373@main
  • Loading branch information
xeenon committed Aug 28, 2023
1 parent 981a048 commit 4bd7a76
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ NS_SWIFT_NAME(_WKWebExtension.MatchPattern)
@result A Boolean value indicating if pattern matches the specified URL.
@seealso matchesURL:options:
*/
- (BOOL)matchesURL:(NSURL *)url NS_SWIFT_UNAVAILABLE("Use options version with empty options set");
- (BOOL)matchesURL:(nullable NSURL *)url NS_SWIFT_UNAVAILABLE("Use options version with empty options set");

/*!
@abstract Matches the reciever pattern against the specified URL with options.
Expand All @@ -151,15 +151,15 @@ NS_SWIFT_NAME(_WKWebExtension.MatchPattern)
@result A Boolean value indicating if pattern matches the specified URL.
@seealso matchesURL:
*/
- (BOOL)matchesURL:(NSURL *)url options:(_WKWebExtensionMatchPatternOptions)options NS_SWIFT_NAME(matches(_:options:));
- (BOOL)matchesURL:(nullable NSURL *)url options:(_WKWebExtensionMatchPatternOptions)options NS_SWIFT_NAME(matches(_:options:));

/*!
@abstract Matches the receiver pattern against the specified pattern.
@param pattern The pattern to match against the receiver pattern.
@result A Boolean value indicating if receiver pattern matches the specified pattern.
@seealso matchesPattern:options:
*/
- (BOOL)matchesPattern:(_WKWebExtensionMatchPattern *)pattern NS_SWIFT_UNAVAILABLE("Use options version with empty options set");
- (BOOL)matchesPattern:(nullable _WKWebExtensionMatchPattern *)pattern NS_SWIFT_UNAVAILABLE("Use options version with empty options set");

/*!
@abstract Matches the receiver pattern against the specified pattern with options.
Expand All @@ -168,7 +168,7 @@ NS_SWIFT_NAME(_WKWebExtension.MatchPattern)
@result A Boolean value indicating if receiver pattern matches the specified pattern.
@seealso matchesPattern:
*/
- (BOOL)matchesPattern:(_WKWebExtensionMatchPattern *)pattern options:(_WKWebExtensionMatchPatternOptions)options NS_SWIFT_NAME(matches(_:options:));
- (BOOL)matchesPattern:(nullable _WKWebExtensionMatchPattern *)pattern options:(_WKWebExtensionMatchPatternOptions)options NS_SWIFT_NAME(matches(_:options:));

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,13 @@ - (BOOL)matchesURL:(NSURL *)urlToMatch

- (BOOL)matchesURL:(NSURL *)urlToMatch options:(_WKWebExtensionMatchPatternOptions)options
{
NSParameterAssert([urlToMatch isKindOfClass:NSURL.class]);
NSAssert(!(options & _WKWebExtensionMatchPatternOptionsMatchBidirectionally), @"Invalid parameter: WKWebExtensionMatchPatternOptionsMatchBidirectionally is not valid when matching a URL");

if (!urlToMatch)
return NO;

NSParameterAssert([urlToMatch isKindOfClass:NSURL.class]);

return _webExtensionMatchPattern->matchesURL(urlToMatch, toImpl(options));
}

Expand Down

0 comments on commit 4bd7a76

Please sign in to comment.