New: type check - CPPasteBoard setString:forType:.

When this method is given e,g, an array or CPData, it now crashes early instead of the pasteboard exhibiting strange behaviour.
This commit is contained in:
Alexander Ljungberg committed 2013-05-15 08:47:43 -07:00
1 parent 6701117945
commit 44a872659a
2 files changed
+20

No files matched your search

+4
View File
@@ -246,6 +246,10 @@ var CPPasteboards = nil,
*/
- (void)setString:(CPString)aString forType:(CPString)aType
{
// Putting a non-string on the string pasteboard can lead to strange crashes.
if (aString && aString.isa && ![aString isKindOfClass:CPString])
[CPException raise:CPInvalidArgumentException reason:"CPPasteboard setString:forType: must be called with a string."];
[self setPropertyList:aString forType:aType];
}
+16
View File
@@ -14,4 +14,20 @@
[self assert:@"hello" equals:[pboard stringForType:CPStringPboardType]];
}
- (void)testSetStringTypeCheck
{
var pboard = [CPPasteboard generalPasteboard];
[pboard declareTypes:@[CPStringPboardType] owner:nil];
// These are okay.
[pboard setString:"a" forType:CPStringPboardType];
[pboard setString:[CPString stringWithString:@"a"] forType:CPStringPboardType];
// This one should crash.
[self assertThrows:function()
{
[pboard setString:[1, 2, 3] forType:CPStringPboardType];
}];
}
@end