[smuxi: 162/179] Engine(-Tests): fix Bitcoin message pattern regex
- From: Mirco M. M. Bauer <mmmbauer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [smuxi: 162/179] Engine(-Tests): fix Bitcoin message pattern regex
- Date: Sat, 4 Nov 2017 05:50:58 +0000 (UTC)
commit 253fc27c292c98ce02f873fbf8aa5da90767a2e1
Author: Mirco Bauer <meebey meebey net>
Date: Tue Jun 20 23:02:45 2017 +0800
Engine(-Tests): fix Bitcoin message pattern regex
The regular expression for matching Bitcoin transaction hashes is matching
parts of a SHA1 hash and Ethereum address as false-positive. The regex is now
including the new delimiter feature that only matches a word, but not within
a word.
src/Engine-Tests/MessageBuilderTests.cs | 16 ++++++++++++++++
src/Engine/Config/MessageBuilderSettings.cs | 11 ++++++++++-
2 files changed, 26 insertions(+), 1 deletions(-)
---
diff --git a/src/Engine-Tests/MessageBuilderTests.cs b/src/Engine-Tests/MessageBuilderTests.cs
index 5d3d847..432537e 100644
--- a/src/Engine-Tests/MessageBuilderTests.cs
+++ b/src/Engine-Tests/MessageBuilderTests.cs
@@ -754,6 +754,22 @@ namespace Smuxi.Engine
}
[Test]
+ public void AppendMessageWithNonBitcoinTxHash()
+ {
+ var msg = "11:45:54 <matt> I so I send to 0x2880502fc7373e73cc19f3e8dd1cd71ca75ad826, correct?";
+ var builder = new MessageBuilder();
+ builder.TimeStamp = DateTime.MinValue;
+ builder.Append(new TextMessagePartModel(msg));
+ TestMessage(msg, builder.ToMessage());
+
+ msg = "19:15:50 <meebey> b7ae3f09f4f1ef58a6bc479541523a7428ab5d30 ../../lib/emoji.json";
+ builder = new MessageBuilder();
+ builder.TimeStamp = DateTime.MinValue;
+ builder.Append(new TextMessagePartModel(msg));
+ TestMessage(msg, builder.ToMessage());
+ }
+
+ [Test]
public void AppendMessageWithEmojis()
{
var msg = "foo :smiley: bar";
diff --git a/src/Engine/Config/MessageBuilderSettings.cs b/src/Engine/Config/MessageBuilderSettings.cs
index 06e6b44..b5955f8 100644
--- a/src/Engine/Config/MessageBuilderSettings.cs
+++ b/src/Engine/Config/MessageBuilderSettings.cs
@@ -149,7 +149,16 @@ namespace Smuxi.Engine
var query = @"(\?[" + path_chars + @"]+)?";
var bitcoin_address_query = bitcoin_address + query;
regex = new Regex(
- @"(?:bitcoin:)?(" + bitcoin_address_query + @")",
+ @"bitcoin:(" + bitcoin_address_query + @")",
+ RegexOptions.IgnoreCase | RegexOptions.Compiled
+ );
+ BuiltinPatterns.Add(new MessagePatternModel(regex) {
+ LinkFormat = "bitcoin:{1}"
+ });
+
+ // bitcoin address (heuristical)
+ regex = new Regex(
+ start_delimiter + @"(" + bitcoin_address_query + @")" + end_delimiter,
RegexOptions.IgnoreCase | RegexOptions.Compiled
);
BuiltinPatterns.Add(new MessagePatternModel(regex) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]