<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -767,19 +767,39 @@ RoxorCore::should_invalidate_inline_op(SEL sel, Class klass)
     abort();
 }
 
+static ID
+sanitize_mid(SEL sel)
+{
+    const char *selname = sel_getName(sel);
+    const size_t sellen = strlen(selname);
+    if (selname[sellen - 1] == ':') {
+	if (memchr(selname, ':', sellen - 1) != NULL) {
+	    return 0;
+	}
+	char buf[100];
+	strncpy(buf, selname, sellen);
+	buf[sellen - 1] = '\0';
+	return rb_intern(buf);
+    }
+    return rb_intern(selname);
+}
+
 void
 RoxorCore::method_added(Class klass, SEL sel)
 {
     if (get_running()) {
 	// Call method_added: or singleton_method_added:.
-	VALUE sym = ID2SYM(rb_intern(sel_getName(sel)));
-        if (RCLASS_SINGLETON(klass)) {
-	    VALUE sk = rb_iv_get((VALUE)klass, &quot;__attached__&quot;);
-	    rb_vm_call(sk, selSingletonMethodAdded, 1, &amp;sym, false);
-        }
-        else {
-	    rb_vm_call((VALUE)klass, selMethodAdded, 1, &amp;sym, false);
-        }
+	ID mid = sanitize_mid(sel);
+	if (mid != 0) {
+	    VALUE sym = ID2SYM(mid);
+	    if (RCLASS_SINGLETON(klass)) {
+		VALUE sk = rb_iv_get((VALUE)klass, &quot;__attached__&quot;);
+		rb_vm_call(sk, selSingletonMethodAdded, 1, &amp;sym, false);
+	    }
+	    else {
+		rb_vm_call((VALUE)klass, selMethodAdded, 1, &amp;sym, false);
+	    }
+	}
     }
 
 }
@@ -2330,13 +2350,16 @@ RoxorCore::undef_method(Class klass, SEL sel)
     ruby_methods.erase(iter);
 #endif
 
-    VALUE sym = ID2SYM(rb_intern(sel_getName(sel)));
-    if (RCLASS_SINGLETON(klass)) {
-	VALUE sk = rb_iv_get((VALUE)klass, &quot;__attached__&quot;);
-	rb_vm_call(sk, selSingletonMethodUndefined, 1, &amp;sym, false);
-    }
-    else {
-	rb_vm_call((VALUE)klass, selMethodUndefined, 1, &amp;sym, false);
+    ID mid = sanitize_mid(sel);
+    if (mid != 0) {
+	VALUE sym = ID2SYM(mid);
+	if (RCLASS_SINGLETON(klass)) {
+	    VALUE sk = rb_iv_get((VALUE)klass, &quot;__attached__&quot;);
+	    rb_vm_call(sk, selSingletonMethodUndefined, 1, &amp;sym, false);
+	}
+	else {
+	    rb_vm_call((VALUE)klass, selMethodUndefined, 1, &amp;sym, false);
+	}
     }
 }
 
@@ -2384,13 +2407,16 @@ RoxorCore::remove_method(Class klass, SEL sel)
     method_setImplementation(m, (IMP)rb_vm_removed_imp);
     invalidate_respond_to_cache();
 
-    VALUE sym = ID2SYM(rb_intern(sel_getName(sel)));
-    if (RCLASS_SINGLETON(klass)) {
-	VALUE sk = rb_iv_get((VALUE)klass, &quot;__attached__&quot;);
-	rb_vm_call(sk, selSingletonMethodRemoved, 1, &amp;sym, false);
-    }
-    else {
-	rb_vm_call((VALUE)klass, selMethodRemoved, 1, &amp;sym, false);
+    ID mid = sanitize_mid(sel);
+    if (mid != 0) {
+	VALUE sym = ID2SYM(mid);
+	if (RCLASS_SINGLETON(klass)) {
+	    VALUE sk = rb_iv_get((VALUE)klass, &quot;__attached__&quot;);
+	    rb_vm_call(sk, selSingletonMethodRemoved, 1, &amp;sym, false);
+	}
+	else {
+	    rb_vm_call((VALUE)klass, selMethodRemoved, 1, &amp;sym, false);
+	}
     }
 }
 </diff>
      <filename>vm.cpp</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2cbd6f478ff9efd1f8149f37875cb3f96169d3a5</id>
    </parent>
  </parents>
  <author>
    <name>lsansonetti@apple.com</name>
    <email>lsansonetti@apple.com@23306eb0-4c56-4727-a40e-e92c0eb68959</email>
  </author>
  <url>http://github.com/masterkain/macruby/commit/a073b7f36e62e36cfb379dadf4a029300ee70b2f</url>
  <id>a073b7f36e62e36cfb379dadf4a029300ee70b2f</id>
  <committed-date>2009-11-07T11:37:46-08:00</committed-date>
  <authored-date>2009-11-07T11:37:46-08:00</authored-date>
  <message>make sure to sanitize method names because passing them to the added/removed/undefined callbacks

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@2979 23306eb0-4c56-4727-a40e-e92c0eb68959</message>
  <tree>ca917f200958f5f38f00e2c1e9c57d0cd86779b4</tree>
  <committer>
    <name>lsansonetti@apple.com</name>
    <email>lsansonetti@apple.com@23306eb0-4c56-4727-a40e-e92c0eb68959</email>
  </committer>
</commit>
