WKRemoteObjectEncoder should escape keys
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Nov 2013 00:09:03 +0000 (00:09 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Nov 2013 00:09:03 +0000 (00:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=123761

Reviewed by Tim Horton.

Keys that start with $ will be reserved for use by the coder, so prepend an extra
$ to keys that already start with $ to avoid clashes.

* Shared/API/Cocoa/WKRemoteObjectCoder.mm:
(escapeKey):
(-[WKRemoteObjectEncoder encodeBytes:length:forKey:]):
(-[WKRemoteObjectEncoder _encodeObjectForKey:usingBlock:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@158610 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/API/Cocoa/WKRemoteObjectCoder.mm

index 927a916..d568428 100644 (file)
@@ -1,3 +1,18 @@
+2013-11-04  Anders Carlsson  <andersca@apple.com>
+
+        WKRemoteObjectEncoder should escape keys
+        https://bugs.webkit.org/show_bug.cgi?id=123761
+
+        Reviewed by Tim Horton.
+
+        Keys that start with $ will be reserved for use by the coder, so prepend an extra
+        $ to keys that already start with $ to avoid clashes.
+
+        * Shared/API/Cocoa/WKRemoteObjectCoder.mm:
+        (escapeKey):
+        (-[WKRemoteObjectEncoder encodeBytes:length:forKey:]):
+        (-[WKRemoteObjectEncoder _encodeObjectForKey:usingBlock:]):
+
 2013-11-04  Benjamin Poulain  <bpoulain@apple.com>
 
         [WK2] Update WebGeolocationManager to support multiple WebContent processes
index 559527e..b19519e 100644 (file)
@@ -91,6 +91,14 @@ using namespace WebKit;
     }];
 }
 
+static NSString *escapeKey(NSString *key)
+{
+    if (key.length && [key characterAtIndex:0] == '$')
+        return [@"$" stringByAppendingString:key];
+
+    return key;
+}
+
 - (void)_encodeInvocation:(NSInvocation *)invocation forKey:(NSString *)key
 {
     [self _encodeObjectForKey:key usingBlock:^{
@@ -150,7 +158,7 @@ using namespace WebKit;
 
 - (void)encodeBytes:(const uint8_t *)bytes length:(NSUInteger)length forKey:(NSString *)key
 {
-    _currentDictionary->set(key, WebData::create(bytes, length));
+    _currentDictionary->set(escapeKey(key), WebData::create(bytes, length));
 }
 
 - (RefPtr<MutableDictionary>)_encodedObjectUsingBlock:(void (^)())block
@@ -165,7 +173,7 @@ using namespace WebKit;
 
 - (void)_encodeObjectForKey:(NSString *)key usingBlock:(void (^)())block
 {
-    _currentDictionary->set(key, [self _encodedObjectUsingBlock:block]);
+    _currentDictionary->set(escapeKey(key), [self _encodedObjectUsingBlock:block]);
 }
 
 @end