From e3c8280464ca4386bfe14fd831ac579c50d9fefa Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Mon, 21 Mar 2011 21:46:59 +0100
Subject: [PATCH] Issue #1097380 by Berdir: Fixed subject consisting of only a space can not be clicked.

---
 privatemsg.module    |    2 ++
 privatemsg.pages.inc |    2 ++
 privatemsg.test      |   14 ++++++++++++++
 3 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/privatemsg.module b/privatemsg.module
index 254586e..cb2cea0 100644
--- a/privatemsg.module
+++ b/privatemsg.module
@@ -1655,6 +1655,8 @@ function _privatemsg_validate_message(&$message, $form = FALSE) {
     }
   }
 
+  // Prevent subjects which only consist of a space as these can not be clicked.
+  $message['subject'] = trim($message['subject']);
   if (empty($message['subject'])) {
     if ($form) {
       form_set_error('subject', t('You must include a subject line with your message.'));
diff --git a/privatemsg.pages.inc b/privatemsg.pages.inc
index f5e7872..616d367 100644
--- a/privatemsg.pages.inc
+++ b/privatemsg.pages.inc
@@ -471,6 +471,8 @@ function privatemsg_new_validate($form, &$form_state) {
   // The actual message that is being sent, we create this during validation and pass to submit to send out.
   $message = $form_state['values'];
   $message['timestamp'] = time();
+  // Avoid subjects which only consist of a space as these can not be clicked.
+  $message['subject'] = trim($message['subject']);
 
   $trimed_body = trim(truncate_utf8(strip_tags($message['body']), 50, TRUE, TRUE));
   if (empty($message['subject']) && !empty($trimed_body)) {
diff --git a/privatemsg.test b/privatemsg.test
index d1cb62f..7fd61f2 100644
--- a/privatemsg.test
+++ b/privatemsg.test
@@ -249,6 +249,12 @@ class PrivatemsgTestCase extends DrupalWebTestCase {
       'subject'     => '',
       'body'        => '',
     );
+    // Empty subject and body.
+    $editonlyspace = array(
+      'recipient'   => $recipient2->name,
+      'subject'     => ' ',
+      'body'        => $this->randomName(10),
+    );
     // Invalid and valid recipient
     $editmixed = array(
       'recipient'   => ($invalidmixed = $this->randomName(5)) . ', ' . $recipient->name,
@@ -287,6 +293,9 @@ class PrivatemsgTestCase extends DrupalWebTestCase {
     $this->drupalPost('messages/new', $editempty, t('Send message'));
     $this->assertText(t('You must include a subject line with your message.'), 'Empty subject message displayed.');
 
+    $this->drupalPost('messages/new', $editonlyspace, t('Send message'));
+    $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient2->name)), 'Message sent confirmation displayed.');
+
     $this->drupalPost('messages/new', $editmixed, t('Send message'));
     $this->assertText(t('A message has been sent to @recipients.', array('@recipients' => $recipient->name)), 'Message sent confirmation displayed.');
     $this->assertText(t('The following recipients will not receive this private message: @recipients.', array('@recipients' => $invalidmixed)), 'Message about non-existing user displayed.');
@@ -298,6 +307,11 @@ class PrivatemsgTestCase extends DrupalWebTestCase {
     $this->drupalLogin($recipient2);
     $this->drupalGet('messages');
 
+    // Check that the message with only a space in the subject uses the body
+    // as subject.
+    $this->clickLink($editonlyspace['body']);
+    $this->drupalGet('messages');
+
     $this->assertNoText($edit['subject'], 'Message sent to other recipient not found.');
     $this->assertText($edit2['subject'], 'Sent message subject found.');
     $this->clickLink($edit2['subject']);
-- 
1.7.4.1

