Bug 134524

Summary: [Cocoa] Ensure that the WebKit bundle version in the user agent string continues to match the current format
Product: WebKit Reporter: Mark Rowe (bdash) <mrowe>
Component: New BugsAssignee: Mark Rowe (bdash) <mrowe>
Status: RESOLVED FIXED    
Severity: Normal    
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 134521, 134522    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch simon.fraser: review+

Description Mark Rowe (bdash) 2014-07-01 16:48:19 PDT
The WebKit version portion of the user agent string has historically had at most three components. There's no guarantee that the WebKit framework's bundle version will be limited in this fashion. We should ensure that the version inserted in to the user agent string continues to match the historical format.

<rdar://problem/17447771>
Comment 1 Mark Rowe (bdash) 2014-07-01 16:50:48 PDT
Created attachment 234217 [details]
Patch
Comment 2 Mark Rowe (bdash) 2014-07-02 11:37:12 PDT
Created attachment 234271 [details]
Patch
Comment 3 Simon Fraser (smfr) 2014-07-02 14:53:13 PDT
Comment on attachment 234271 [details]
Patch

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

> Source/WebCore/page/cocoa/UserAgent.mm:69
> +    // We include at most three components of the bundle version in the user agent string.
> +    NSString *bundleVersion = userVisibleWebKitBundleVersionFromFullVersion(fullWebKitVersion);
> +    NSScanner *scanner = [NSScanner scannerWithString:bundleVersion];
> +    NSInteger periodCount = 0;
> +    while (true) {
> +        if (![scanner scanUpToString:@"." intoString:nullptr] || scanner.isAtEnd)
> +            return bundleVersion;
> +
> +        if (++periodCount == 3)
> +            return [bundleVersion substringToIndex:scanner.scanLocation];
> +
> +        ++scanner.scanLocation;
> +    }
> +
> +    ASSERT_NOT_REACHED();

Can we do this in C++?
Comment 4 Mark Rowe (bdash) 2014-07-02 14:57:28 PDT
(In reply to comment #3)
> (From update of attachment 234271 [details])
> Can we do this in C++?

It seemed preferable for the code to match our other internal implementation rather than writing it twice.
Comment 5 Mark Rowe (bdash) 2014-07-02 16:04:29 PDT
Landed in r170735.
<https://trac.webkit.org/r170735>