From 4ec5f00b1dec8220c1e458d852eecd602dd56b8f Mon Sep 17 00:00:00 2001 From: rsgowman Date: Thu, 30 Nov 2017 13:41:26 -0500 Subject: Fix StringView to properly convert NSStrings (#509) NSStrings are utf16, so NSString::length returns the number of utf16 characters present in the string. When the string is entirely made up of US-ASCII characters, everything's fine. But when characters requiring 16 bits are present, the size calculations were incorrect. Fixed by calculating the length based on the destination character set (i.e. UTF8). --- Firestore/Source/Local/StringView.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Firestore/Source/Local') diff --git a/Firestore/Source/Local/StringView.h b/Firestore/Source/Local/StringView.h index 799baf8..b81b7b5 100644 --- a/Firestore/Source/Local/StringView.h +++ b/Firestore/Source/Local/StringView.h @@ -46,7 +46,8 @@ class StringView { // Creates a StringView from an NSString. When StringView is an argument type // into which an NSString* is passed, the caller should ensure that the // NSString is retained. - StringView(NSString *str) : data_([str UTF8String]), size_(str.length) { + StringView(NSString *str) + : data_([str UTF8String]), size_([str lengthOfBytesUsingEncoding:NSUTF8StringEncoding]) { } // Creates a StringView from the given char* pointer with an explicit size. -- cgit v1.2.3