@@ -61,13 +61,30 @@ static CFNumberType PFNumberTypeForObjCType(const char *encodedType) {
61
61
[' f' ] = kCFNumberFloatType ,
62
62
[' d' ] = kCFNumberDoubleType ,
63
63
64
- // C99 & CXX boolean
64
+ // C99 & CXX boolean. We are keeping this here for decoding, as you can safely use CFNumberGetBytes on a
65
+ // CFBoolean, and extract it into a char.
65
66
[' B' ] = kCFNumberCharType ,
66
67
};
67
68
68
69
return (CFNumberType )types[encodedType[0 ]];
69
70
}
70
71
72
+ static NSNumber *PFNumberCreateSafe (const char *typeEncoding, const void *bytes) {
73
+ // NOTE: This is required because NSJSONSerialization treats all NSNumbers with the 'char' type as numbers, not
74
+ // booleans. As such, we must treat any and all boolean type encodings as explicit booleans, otherwise we will
75
+ // send '1' and '0' to the api server rather than 'true' and 'false'.
76
+ //
77
+ // TODO (richardross): When we drop support for 10.9/iOS 7, remove the 'c' encoding and only use the new 'B'
78
+ // encoding.
79
+ if (typeEncoding[0 ] == ' B' || typeEncoding[0 ] == ' c' ) {
80
+ return [NSNumber numberWithBool: *(BOOL *)bytes];
81
+ }
82
+
83
+ CFNumberType numberType = PFNumberTypeForObjCType (typeEncoding);
84
+ PFConsistencyAssert (numberType != kCFNumberTypeUnknown , @" Unsupported type encoding %s !" , typeEncoding);
85
+ return (__bridge_transfer NSNumber *)CFNumberCreate (NULL , numberType, typeEncoding);
86
+ }
87
+
71
88
@implementation PFObjectSubclassingController {
72
89
dispatch_queue_t _registeredSubclassesAccessQueue;
73
90
NSMutableDictionary *_registeredSubclasses;
@@ -230,11 +247,7 @@ - (void)_forwardSetterInvocation:(NSInvocation *)invocation
230
247
dictionaryValue = [dictionaryValue copy ];
231
248
}
232
249
} else {
233
- CFNumberType numberType = PFNumberTypeForObjCType (argumentType);
234
- PFConsistencyAssert (numberType != kCFNumberTypeUnknown , @" Unsupported type encoding %s !" , argumentType);
235
-
236
- CFNumberRef number = CFNumberCreate (NULL , numberType, argumentValueBytes);
237
- dictionaryValue = (__bridge_transfer id )number;
250
+ dictionaryValue = PFNumberCreateSafe (argumentType, argumentValueBytes);
238
251
}
239
252
240
253
if (dictionaryValue == nil ) {
0 commit comments