From eced6a8764de7830a2e90e65d6bbf965159e5c1e Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Sat, 30 Sep 2017 14:55:39 +0200 Subject: [PATCH] utils: support URLs with ',' inside --- src/mconnect/utils.vala | 2 +- test/mconn-utils-test.vala | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/mconnect/utils.vala b/src/mconnect/utils.vala index f5d796b..5c41557 100644 --- a/src/mconnect/utils.vala +++ b/src/mconnect/utils.vala @@ -162,7 +162,7 @@ using Posix; string[] find_urls(string text) { try { // regex taken from SO - Regex r = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/=]*)/; + Regex r = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+,.~#?&\/=]*)/; MatchInfo mi; diff --git a/test/mconn-utils-test.vala b/test/mconn-utils-test.vala index 0a1a2a6..ee527a9 100644 --- a/test/mconn-utils-test.vala +++ b/test/mconn-utils-test.vala @@ -34,6 +34,16 @@ void test_find_urls_none() { assert(urls.length == 0); } +void test_find_urls_special() { + var urls = Utils.find_urls("http://foo.bar.com/123,345%20,,,/foo.html"); + + assert(urls != null); + assert(urls.length == 1); + + assert(urls[0] == "http://foo.bar.com/123,345%20,,,/foo.html"); +} + + public static void main(string[] args) { Test.init(ref args); @@ -42,5 +52,6 @@ public static void main(string[] args) { Test.add_func("/mconn-utils/find-urls/extract", test_find_urls_extract); Test.add_func("/mconn-utils/find-urls/many", test_find_urls_many); Test.add_func("/mconn-utils/find-urls/none", test_find_urls_none); + Test.add_func("/mconn-utils/find-urls/special", test_find_urls_special); Test.run(); } \ No newline at end of file