mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-20 13:39:22 +00:00
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:
1 parent
6701117945
commit
44a872659a
2 files changed
+20
No files matched your search
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user