Browse Source

utils: support URLs with ',' inside

bboozzoo/self-announce
Maciek Borzecki 7 years ago
parent
commit
eced6a8764
2 changed files with 12 additions and 1 deletions
  1. +1
    -1
      src/mconnect/utils.vala
  2. +11
    -0
      test/mconn-utils-test.vala

+ 1
- 1
src/mconnect/utils.vala View File

@ -162,7 +162,7 @@ using Posix;
string[] find_urls(string text) { string[] find_urls(string text) {
try { try {
// regex taken from SO // 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; MatchInfo mi;


+ 11
- 0
test/mconn-utils-test.vala View File

@ -34,6 +34,16 @@ void test_find_urls_none() {
assert(urls.length == 0); 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) { public static void main(string[] args) {
Test.init(ref 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/extract", test_find_urls_extract);
Test.add_func("/mconn-utils/find-urls/many", test_find_urls_many); 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/none", test_find_urls_none);
Test.add_func("/mconn-utils/find-urls/special", test_find_urls_special);
Test.run(); Test.run();
} }

Loading…
Cancel
Save