Bug 130889

Summary: Fix recently-introduced off-by-one error in centerTruncateToBuffer
Product: WebKit Reporter: Darin Adler <darin>
Component: WebKit Misc.Assignee: Darin Adler <darin>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, conrad_shultz
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch ap: review+

Description Darin Adler 2014-03-27 23:42:35 PDT
Fix recently-introduced off-by-one error in centerTruncateToBuffer
Comment 1 Darin Adler 2014-03-28 00:14:38 PDT
I finished the fix about an hour ago, but I decided to add unit tests for WebStringTruncator, which is taking me a little time.
Comment 2 Darin Adler 2014-03-28 00:36:55 PDT
Created attachment 228030 [details]
Patch
Comment 3 Darin Adler 2014-03-28 00:37:49 PDT
I originally thought this was Mac-only, but it seems this code is used on other platforms as well.
Comment 4 Alexey Proskuryakov 2014-03-28 10:07:56 PDT
Comment on attachment 228030 [details]
Patch

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

> Source/WebKit/mac/ChangeLog:12
> +        (+[WebStringTruncator initialize]): Added threading initialization, needed for main
> +        thread assertions in string truncator code.

I'm confused about how this worked before - you didn't add any new assertions in this patch. Is something like this needed on iOS too?
Comment 5 Conrad Shultz 2014-03-28 11:58:31 PDT
Would it be worth adding some non-ASCII inputs to the unit tests?
Comment 6 Darin Adler 2014-03-28 17:44:21 PDT
Comment on attachment 228030 [details]
Patch

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

> Source/WebKit/mac/Misc/WebStringTruncator.mm:67
> +#if PLATFORM(MAC)

As Alexey and I discussed, we don’t need this #if since this file is already Mac-only (has NSFont).
Comment 7 Darin Adler 2014-03-28 20:18:50 PDT
Committed r166448: <http://trac.webkit.org/changeset/166448>
Comment 8 Alexey Proskuryakov 2014-03-29 22:49:16 PDT
The regression test fails on Mountain Lion:

/Volumes/Data/slave/mountainlion-debug/build/Tools/TestWebKitAPI/Tests/mac/StringTruncator.mm:36: Failure
Value of: "abcdef…tuvwxyz"
Expected: [[WebStringTruncator centerTruncateString:@"abcdefghijklmnopqrstuvwxyz" toWidth:100 withFont:[NSFont fontWithName:@"Helvetica" size:12]] UTF8String]
Which is: "abcdefg…tuvwxyz"
Comment 9 Alexey Proskuryakov 2014-03-29 22:59:13 PDT
Updated expectation for 10.8 in <http://trac.webkit.org/r166458>.