From df2ad14297e264365c37435cf64672ea3920ea10 Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Wed, 11 Feb 2015 19:55:09 +0100
Subject: Do not try highlight words if no text and background colours are
 specified

The tests have been adjusted so a colour is set in their highlight
actions.

Test-Information:

Tested with a "own nick" highlight rule with a "No highlight" action
and one with highlights colours set. The cases now work as expected.

Added a unit test that checks that no highlighting happens when no
colour is specified.

Change-Id: Ied48d8c2e033531c1b0532348b9380e1bd884b44

diff --git a/Swift/Controllers/Chat/ChatMessageParser.cpp b/Swift/Controllers/Chat/ChatMessageParser.cpp
index fe61724..666ec2f 100644
--- a/Swift/Controllers/Chat/ChatMessageParser.cpp
+++ b/Swift/Controllers/Chat/ChatMessageParser.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2014 Isode Limited.
+ * Copyright (c) 2013-2015 Isode Limited.
  * All rights reserved.
  * See the COPYING file for more information.
  */
@@ -148,6 +148,8 @@ namespace Swift {
 				continue; /* this rule only applies to MUC's, and this is a CHAT */
 			} else if (rule.getMatchChat() && mucMode_) {
 				continue; /* this rule only applies to CHAT's, and this is a MUC */
+			} else if (rule.getAction().getTextBackground().empty() && rule.getAction().getTextColor().empty()) {
+				continue; /* do not try to highlight text, if no highlight color is specified */
 			}
 			const std::vector<boost::regex> keywordRegex = rule.getKeywordRegex(nick);
 			foreach(const boost::regex& regex, keywordRegex) {
diff --git a/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp
index 1192c8f..1b92bb6 100644
--- a/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/ChatMessageParserTest.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2014 Isode Limited.
+ * Copyright (c) 2013-2015 Isode Limited.
  * All rights reserved.
  * See the COPYING file for more information.
  */
@@ -20,6 +20,7 @@ class ChatMessageParserTest : public CppUnit::TestFixture {
 	CPPUNIT_TEST(testHiddenEmoticon);
 	CPPUNIT_TEST(testEndlineEmoticon);
 	CPPUNIT_TEST(testBoundedEmoticons);
+	CPPUNIT_TEST(testNoColourNoHighlight);
 	CPPUNIT_TEST_SUITE_END();
 	
 public:
@@ -67,6 +68,7 @@ public:
 		rule.setMatchCase(matchCase);
 		rule.setMatchWholeWords(matchWholeWord);
 		rule.setMatchChat(true);
+		rule.getAction().setTextBackground("white");
 		return rule;
 	}
 
@@ -85,13 +87,16 @@ public:
 		return list;
 	}
 
-	static HighlightRulesListPtr ruleListWithNickHighlight()
+	static HighlightRulesListPtr ruleListWithNickHighlight(bool withHighlightColour = true)
 	{
 		HighlightRule rule;
 		rule.setMatchChat(true);
 		rule.setNickIsKeyword(true);
 		rule.setMatchCase(true);
 		rule.setMatchWholeWords(true);
+		if (withHighlightColour) {
+			rule.getAction().setTextBackground("white");
+		}
 		boost::shared_ptr<HighlightManager::HighlightRulesList> list = boost::make_shared<HighlightManager::HighlightRulesList>();
 		list->addRule(rule);
 		return list;
@@ -256,6 +261,12 @@ public:
 		assertText(result, 2, ")");
 	}
 
+	void testNoColourNoHighlight() {
+		ChatMessageParser testling(emoticons_, ruleListWithNickHighlight(false));
+		ChatWindow::ChatMessage result = testling.parseMessageBody("Alice", "Alice");
+		assertText(result, 0, "Alice");
+	}
+
 private:
 	std::map<std::string, std::string> emoticons_;
 	std::string smile1_;
-- 
cgit v0.10.2-6-g49f6