From bdb46141942d11a461d11924692da187043fcfc8 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Tue, 19 Feb 2013 22:59:50 +0100
Subject: [PATCH] - #1719470 by sun: Fixed Delete link for blacklist terms
 does not escape slashes.

Fixed blacklist entry IDs are not URL-encoded.
---
 includes/mollom.class.inc |  8 +++++---
 mollom.admin.css          | 12 ++++++++++++
 mollom.admin.inc          | 45 +++++++++++++++++++++------------------------
 mollom.module             |  2 +-
 4 files changed, 39 insertions(+), 28 deletions(-)
 create mode 100644 mollom.admin.css

diff --git a/includes/mollom.class.inc b/includes/mollom.class.inc
index 1059232..8659528 100644
--- a/includes/mollom.class.inc
+++ b/includes/mollom.class.inc
@@ -1216,7 +1216,8 @@ abstract class Mollom {
     if (!isset($publicKey)) {
       $publicKey = $this->publicKey;
     }
-    $result = $this->query('GET', 'blacklist/' . $publicKey . '/' . $entryId, array(), array('entry', 'id'));
+    $path = 'blacklist/' . $publicKey . '/' . rawurlencode($entryId);
+    $result = $this->query('GET', $path, array(), array('entry', 'id'));
     return isset($result['entry']) ? $result['entry'] : $result;
   }
 
@@ -1242,7 +1243,7 @@ abstract class Mollom {
     }
     $path = 'blacklist/' . $publicKey;
     if (!empty($data['id'])) {
-      $path .= '/' . $data['id'];
+      $path .= '/' . rawurlencode($data['id']);
       unset($data['id']);
     }
     $result = $this->query('POST', $path, $data, array('entry', 'id'));
@@ -1265,7 +1266,8 @@ abstract class Mollom {
     if (!isset($publicKey)) {
       $publicKey = $this->publicKey;
     }
-    $result = $this->query('POST', 'blacklist/' . $publicKey . '/' . $entryId . '/delete');
+    $path = 'blacklist/' . $publicKey . '/' . rawurlencode($entryId) . '/delete';
+    $result = $this->query('POST', $path);
     return $this->lastResponseCode === TRUE;
   }
 }
diff --git a/mollom.admin.css b/mollom.admin.css
new file mode 100644
index 0000000..7dddc75
--- /dev/null
+++ b/mollom.admin.css
@@ -0,0 +1,12 @@
+
+/**
+ * Override common theme styles for form actions and buttons.
+ *
+ * Themes typically apply margins to the .form-actions container and form
+ * buttons, which adds too much vertical spacing to the first table row in the
+ * blacklist table.
+ */
+#mollom-blacklist .form-actions,
+#mollom-blacklist .form-submit {
+  margin: 0;
+}
diff --git a/mollom.admin.inc b/mollom.admin.inc
index 8d54877..5f194b7 100644
--- a/mollom.admin.inc
+++ b/mollom.admin.inc
@@ -456,6 +456,7 @@ function mollom_admin_unprotect_form_submit($form, &$form_state) {
  */
 function mollom_admin_blacklist_form(&$form_state, $type = 'spam') {
   $form['#tree'] = TRUE;
+  drupal_add_css(drupal_get_path('module', 'mollom') . '/mollom.admin.css');
 
   // Translate internal reason values for rendering and select list in form.
   $contexts = array(
@@ -479,25 +480,24 @@ function mollom_admin_blacklist_form(&$form_state, $type = 'spam') {
       if ($entry['reason'] != $type) {
         continue;
       }
+      $row = array();
       // #class property is internally used by
       // theme_mollom_admin_blacklist_form().
-      $row = array(
-        'context' => array(
-          '#value' => check_plain($contexts[$entry['context']]),
-          '#class' => 'mollom-blacklist-context value-' . check_plain($entry['context']),
-        ),
-        'match' => array(
-          '#value' => check_plain($matches[$entry['match']]),
-          '#class' => 'mollom-blacklist-match value-' . check_plain($entry['match']),
-        ),
-        'value' => array(
-          '#value' => check_plain($entry['value']),
-          '#class' => 'mollom-blacklist-value',
-        ),
+      $row['context'] = array(
+        '#value' => check_plain($contexts[$entry['context']]),
+        '#class' => 'mollom-blacklist-context value-' . check_plain($entry['context']),
+      );
+      $row['match'] = array(
+        '#value' => check_plain($matches[$entry['match']]),
+        '#class' => 'mollom-blacklist-match value-' . check_plain($entry['match']),
+      );
+      $row['value'] = array(
+        '#value' => check_plain($entry['value']),
+        '#class' => 'mollom-blacklist-value',
       );
       $row['actions']['delete'] = array(
-        '#value' => l(t('delete'), 'admin/settings/mollom/blacklist/delete/' . $entry['id'], array(
-          'query' => drupal_get_destination(),
+        '#value' => l(t('delete'), 'admin/settings/mollom/blacklist/delete', array(
+          'query' => 'id=' . rawurlencode($entry['id']) . '&' . drupal_get_destination(),
         )),
       );
       $form['blacklist'][$entry['id']] = $row;
@@ -634,18 +634,15 @@ function theme_mollom_admin_blacklist_form($form) {
 /**
  * Form builder; Builds the confirmation form for deleting a blacklist item.
  *
- * @param $key
- *   The blacklist entry text to remove, base64-encoded.
- * @param $context
- *   The context of the blacklist entry.
- * @param $reason
- *   The reason of the blacklist entry.
- *
  * @ingroup forms
  * @see mollom_admin_blacklist_delete_submit()
  */
-function mollom_admin_blacklist_delete(&$form_state, $entryId) {
-  $entry = mollom()->getBlacklistEntry($entryId);
+function mollom_admin_blacklist_delete(&$form_state) {
+  $id = $_GET['id'];
+  if (empty($id) || !($entry = mollom()->getBlacklistEntry($id))) {
+    drupal_not_found();
+    return;
+  }
   $form['entry'] = array(
     '#type' => 'value',
     '#value' => $entry,
diff --git a/mollom.module b/mollom.module
index 538d7dc..0b021d9 100644
--- a/mollom.module
+++ b/mollom.module
@@ -228,7 +228,7 @@ function mollom_menu() {
     'file' => 'mollom.admin.inc',
   );
   $items['admin/settings/mollom/blacklist/delete'] = array(
-    'title' => 'Delete',
+    'title' => 'Delete blacklist entry',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('mollom_admin_blacklist_delete'),
     'access arguments' => array('administer mollom'),
-- 
1.7.11.msysgit.1

