]> err.no Git - scalable-opengroupware.org/commitdiff
proper escaping/unescaping for contacts
authorznek <znek@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Wed, 20 Oct 2004 15:47:45 +0000 (15:47 +0000)
committerznek <znek@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Wed, 20 Oct 2004 15:47:45 +0000 (15:47 +0000)
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@415 d1b88da0-ebda-0310-925b-ed51d893ca5b

12 files changed:
SOGo/SOGo.xcode/project.pbxproj
SOGo/UI/Anais/AnaisAttendeeSelector.m
SOGo/UI/Anais/ChangeLog
SOGo/UI/Anais/Version
SOGo/UI/Contacts/ChangeLog
SOGo/UI/Contacts/UIxContactsSelectionView.m
SOGo/UI/Contacts/Version
SOGo/UI/SOGoUI/ChangeLog
SOGo/UI/SOGoUI/GNUmakefile
SOGo/UI/SOGoUI/SOGoJSStringFormatter.h [new file with mode: 0644]
SOGo/UI/SOGoUI/SOGoJSStringFormatter.m [new file with mode: 0644]
SOGo/UI/SOGoUI/Version

index c8f05b9b6921f86245f0a17c962268d3c23399f9..a5a783e804ae5b345dd8771425743391534393cd 100644 (file)
                                AD0712CB06C917A600A9EEF4,
                                AD071C7D06CD214600A9EEF4,
                                AD071C7E06CD214700A9EEF4,
+                               ADBE3C490726AF4C000FEA6A,
+                               ADBE3C4A0726AF4C000FEA6A,
                        );
                        isa = PBXGroup;
                        path = SOGoUI;
                        refType = 4;
                        sourceTree = "<group>";
                };
+               ADBE3C490726AF4C000FEA6A = {
+                       fileEncoding = 5;
+                       indentWidth = 2;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
+                       path = SOGoJSStringFormatter.h;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               ADBE3C4A0726AF4C000FEA6A = {
+                       fileEncoding = 5;
+                       indentWidth = 2;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
+                       path = SOGoJSStringFormatter.m;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
                ADCDE53106ADA8AC00BFCE2B = {
                        fileEncoding = 5;
                        indentWidth = 8;
index 676b4d0bfbed541a446008aa0d71b2ccb49088dd..d8474b2ca3dc71f8db7bc233e4eb3b7cde15ad9e 100644 (file)
@@ -285,34 +285,41 @@ static BOOL debugOn = NO;
   ctx = [self context];
   if (![[ctx valueForKey:@"HasAddTableAnaisAttendeeSelector"] boolValue]) {
     static NSString *script = \
+      @"function unescapeCallbackParameter(s) {\n"
+      @"  s = s.replace(/&apos;/g, \"'\");\n"
+      @"  s = s.replace(/&quot;/g, '\"');\n"
+      @"  return s;\n"
+      @"}\n"
+      @"\n"
       @"function addToTable(tableId, type, cn, dn, email, uid, sn) {\n"
-      @"  var test = document.getElementById(email);"
-      @"  if(test)"
-      @"    return;"
-      @""
-      @"  var table = document.getElementById(tableId);"
-      @"  var tr = document.createElement('tr');"
-      @"  var td, checkbox, text;"
-      @""
-      @"  td = document.createElement('td');"
-      @"  checkbox = document.createElement('input');"
-      @"  checkbox.setAttribute('type', 'checkbox');"
-      @"  checkbox.setAttribute('checked', 'checked');"
-      @"  checkbox.setAttribute('value', email + ';' + cn);"
-      @"  checkbox.setAttribute('id', email);"
-      @"  checkbox.setAttribute('name', tableId);"
-      @"  td.appendChild(checkbox);"
-      @"  tr.appendChild(td);"
-      @"  td = document.createElement('td');"
-      @"  text = document.createTextNode(cn);"
-      @"  td.appendChild(text);"
-      @"  tr.appendChild(td);"
-      @"  table.appendChild(tr);"
+      @"  var test = document.getElementById(email);\n"
+      @"  if(test)\n"
+      @"    return;\n"
+      @"\n"
+      @"  var table = document.getElementById(tableId);\n"
+      @"  var tr = document.createElement('tr');\n"
+      @"  var td, checkbox, text;\n"
+      @"\n"
+      @"  cn = this.unescapeCallbackParameter(cn);\n"
+      @"  td = document.createElement('td');\n"
+      @"  checkbox = document.createElement('input');\n"
+      @"  checkbox.setAttribute('type', 'checkbox');\n"
+      @"  checkbox.setAttribute('checked', 'checked');\n"
+      @"  checkbox.setAttribute('value', email + ';' + cn);\n"
+      @"  checkbox.setAttribute('id', email);\n"
+      @"  checkbox.setAttribute('name', tableId);\n"
+      @"  td.appendChild(checkbox);\n"
+      @"  tr.appendChild(td);\n"
+      @"  td = document.createElement('td');\n"
+      @"  text = document.createTextNode(cn);\n"
+      @"  td.appendChild(text);\n"
+      @"  tr.appendChild(td);\n"
+      @"  table.appendChild(tr);\n"
       @"}\n";
     [ms appendString:script];
     
     [ctx takeValue:[NSNumber numberWithBool:YES]
-        forKey:@"HasAddTableAnaisAttendeeSelector"];
+              forKey:@"HasAddTableAnaisAttendeeSelector"];
   }
   
   s = 
index 2edcc70a09468eb3373f4be46753487a6610acbb..78c05da315db4393b9787e75d41f5b5358902a92 100644 (file)
@@ -1,3 +1,8 @@
+2004-10-20  Marcus Mueller  <znek@mulle-kybernetik.com>
+
+       * AnaisAttendeeSelector.m: provide proper unescaping of special HTML
+         entities via new unescape function. (v0.9.17)
+
 2004-10-18  Marcus Mueller  <znek@mulle-kybernetik.com>
 
        * v0.9.16
index 3ec1cfd088446903dd02e2d761e4f2d5e33eca73..f929c4cecad4e6140b8b068a09cf930bdbb54abb 100644 (file)
@@ -1,3 +1,3 @@
 # $Id: Version 165 2004-08-05 17:55:50Z znek $
 
-SUBMINOR_VERSION:=16
+SUBMINOR_VERSION:=17
index d11dda71be5803659f6bc7cfc4e1d455bf28c563..3af0a4a84dc47e69f012116e238ab9366db7654c 100644 (file)
@@ -1,3 +1,10 @@
+2004-10-20  Marcus Mueller  <znek@mulle-kybernetik.com>
+
+       * UIxContactsSelectionView.m: several properties provided to the
+         callback need to be unescaped properly before being passed back.
+         This is achieved by using the new SOGoJSStringFormatter in SOGoUI.
+         (v0.9.16)
+
 2004-10-14  Marcus Mueller  <znek@mulle-kybernetik.com>
 
        * UIxContactSelector.m: fixed wrong method name (v0.9.15)
index 4c6baba12d892135ae2e06633bcf97ae03b1d86e..4d0fd86b40d7ff2900a773d93ef874a3068e63d4 100644 (file)
 
 
 #include "UIxContactsListView.h"
+#include <SOGoUI/SOGoJSStringFormatter.h>
 
 @interface UIxContactsSelectionView : UIxContactsListView
 {
   NSString *callback;
 }
+
+- (NSString *)_getCN;
+- (NSString *)getCN;
+- (NSString *)getSN;
+- (NSString *)getMail;
+- (NSString *)getUID;
+  
 @end
 
 #include "common.h"
 
 @implementation UIxContactsSelectionView
 
+static SOGoJSStringFormatter *jsFormatter = nil;
+
++ (void)initialize {
+  static BOOL didInit = NO;
+
+  if(didInit)
+    return;
+
+  didInit = YES;
+  jsFormatter = [SOGoJSStringFormatter sharedFormatter];
+}
+
 - (void)dealloc {
   [self->callback release];
   [super dealloc];
   return self->callback;
 }
 
+- (NSString *)_getCN {
+  NSString *sn, *gn;
+
+  sn = [self->contact valueForKey:@"sn"];
+  gn = [self->contact valueForKey:@"givenname"];
+
+  if((!sn || [sn length] == 0) &&
+     (!gn || [gn length] == 0)) {
+    return @"";
+  } else if(!sn || [sn length] == 0) {
+    return gn;
+  } else if(!gn || [gn length] == 0) {
+    return sn;
+  }
+  return [NSString stringWithFormat:@"%@ %@", sn, gn];
+}
+
+- (NSString *)getCN {
+  return [jsFormatter stringByEscapingQuotesInString:[self _getCN]];
+}
+
+- (NSString *)getSN {
+  NSString *sn = [self->contact valueForKey:@"sn"];
+  return [jsFormatter stringByEscapingQuotesInString:sn];
+}
+
+- (NSString *)getMail {
+  return [self->contact valueForKey:@"mail"];
+}
+
+- (NSString *)getUID {
+  return [[AgenorUserManager sharedUserManager] getUIDForEmail:[self getMail]];
+}
+
 - (NSString *)jsOnClickCode {
   /* callback parameters: (type, cn, dn, email, uid, sn) */
   static NSString *jsCode = \
     @"javascript:opener.window.%@('', '%@', '', '%@', '%@', '%@');";
-  NSString *sn, *cn, *mail, *uid;
 
-  sn = [self->contact valueForKey:@"sn"];
-  cn = [NSString stringWithFormat:@"%@ %@",
-    sn,
-    [self->contact valueForKey:@"givenname"]];
-  mail = [self->contact valueForKey:@"mail"];
-  uid = [[AgenorUserManager sharedUserManager] getUIDForEmail:mail];
   return [NSString stringWithFormat:jsCode,
     [self callback],
-    cn,
-    mail,
-    uid,
-    sn];
+    [self getCN],
+    [self getMail],
+    [self getUID],
+    [self getSN]];
 }
 
 @end /* UIxContactsInlineListView */
index cf9e5c1262bbe256db9dcbe38538f8ad07693b99..dee27ead1e663fb7d92a035e999a839f60b6a4c9 100644 (file)
@@ -1,3 +1,5 @@
 # $Id$
 
-SUBMINOR_VERSION:=15
+SUBMINOR_VERSION:=16
+
+# v0.9.16 requires libSOGoUI v0.9.16
index 7866f5b6c0ad6bb3d73622d492a7bd07a164c3b5..db811fb7384f5f77b603c731c2e04bda4266f75c 100644 (file)
@@ -1,3 +1,8 @@
+2004-10-20  Marcus Mueller  <znek@mulle-kybernetik.com>
+
+       * SOGoJSStringFormatter.[hm]: new formatter to properly escape certain
+         strings passed to JavaScript (v0.9.16)
+         
 2004-10-18  Marcus Mueller  <znek@mulle-kybernetik.com>
 
        * UIxComponent.m: changed the implementation of -ownPath and fixed a
index ff9bc807615e6dc8805f73842ead440b387421a2..0f1a66a7874ad66fa7fc872c57c5c2973230b89a 100644 (file)
@@ -11,11 +11,13 @@ libSOGoUI_HEADER_FILES +=   \
        UIxComponent.h          \
        SOGoDateFormatter.h     \
        SOGoAptFormatter.h      \
+       SOGoJSStringFormatter.h \
 
 libSOGoUI_OBJC_FILES +=                \
        UIxComponent.m          \
        SOGoDateFormatter.m     \
        SOGoAptFormatter.m      \
+       SOGoJSStringFormatter.m \
 
 # make
 
diff --git a/SOGo/UI/SOGoUI/SOGoJSStringFormatter.h b/SOGo/UI/SOGoUI/SOGoJSStringFormatter.h
new file mode 100644 (file)
index 0000000..3a59e76
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+  Copyright (C) 2000-2004 SKYRIX Software AG
+
+  This file is part of OGo
+
+  OGo is free software; you can redistribute it and/or modify it under
+  the terms of the GNU Lesser General Public License as published by the
+  Free Software Foundation; either version 2, or (at your option) any
+  later version.
+
+  OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+  License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with OGo; see the file COPYING.  If not, write to the
+  Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+  02111-1307, USA.
+*/
+// $Id$
+
+
+#ifndef        __SOGoJSStringFormatter_H_
+#define        __SOGoJSStringFormatter_H_
+
+
+#import <Foundation/Foundation.h>
+#include <NGExtensions/NSString+Escaping.h>
+
+@interface SOGoJSStringFormatter : NSObject <NGStringEscaping>
+{
+}
+
++ (id)sharedFormatter;
+
+- (NSString *)stringByEscapingQuotesInString:(NSString *)_s;
+- (NSString *)stringByEscapingSingleQuotesInString:(NSString *)_s;
+- (NSString *)stringByEscapingDoubleQuotesInString:(NSString *)_s;
+
+@end
+
+#endif /* __SOGoJSStringFormatter_H_ */
diff --git a/SOGo/UI/SOGoUI/SOGoJSStringFormatter.m b/SOGo/UI/SOGoUI/SOGoJSStringFormatter.m
new file mode 100644 (file)
index 0000000..9b566d0
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+  Copyright (C) 2000-2004 SKYRIX Software AG
+
+  This file is part of OGo
+
+  OGo is free software; you can redistribute it and/or modify it under
+  the terms of the GNU Lesser General Public License as published by the
+  Free Software Foundation; either version 2, or (at your option) any
+  later version.
+
+  OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+  License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with OGo; see the file COPYING.  If not, write to the
+  Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+  02111-1307, USA.
+*/
+// $Id$
+
+
+#include "SOGoJSStringFormatter.h"
+#include "common.h"
+
+@implementation SOGoJSStringFormatter
+
+static NSCharacterSet *quotesSet = nil;
+static NSCharacterSet *squoteSet = nil;
+static NSCharacterSet *dquoteSet = nil;
+
++ (void)initialize {
+  static BOOL didInit = NO;
+  
+  if(didInit)
+    return;
+  
+  didInit   = YES;
+  quotesSet = \
+    [[NSCharacterSet characterSetWithCharactersInString:@"'\""] retain];
+  squoteSet = \
+    [[NSCharacterSet characterSetWithCharactersInString:@"'"] retain];
+  dquoteSet = \
+    [[NSCharacterSet characterSetWithCharactersInString:@"\""] retain];
+}
+
++ (id)sharedFormatter {
+  static id sharedInstance = nil;
+  if(!sharedInstance) {
+    sharedInstance = [[self alloc] init];
+  }
+  return sharedInstance;
+}
+
+- (NSString *)stringByEscapingQuotesInString:(NSString *)_s {
+  return [_s stringByEscapingCharactersFromSet:quotesSet
+             usingStringEscaping:self];
+}
+
+- (NSString *)stringByEscapingSingleQuotesInString:(NSString *)_s {
+  return [_s stringByEscapingCharactersFromSet:squoteSet
+             usingStringEscaping:self];
+}
+
+- (NSString *)stringByEscapingDoubleQuotesInString:(NSString *)_s {
+  return [_s stringByEscapingCharactersFromSet:dquoteSet
+             usingStringEscaping:self];
+}
+
+- (NSString *)stringByEscapingString:(NSString *)_s {
+  if([_s isEqualToString:@"'"]) {
+    return @"&amp;apos;";
+  }
+  return @"&amp;quot;";
+}
+
+@end
index cf9e5c1262bbe256db9dcbe38538f8ad07693b99..27f42dca521c102631a68b11d5a0fab575d2dd28 100644 (file)
@@ -1,3 +1,3 @@
 # $Id$
 
-SUBMINOR_VERSION:=15
+SUBMINOR_VERSION:=16