Skip to content
Snippets Groups Projects
Commit c6108f0f authored by Lynx Linden's avatar Lynx Linden
Browse files

EXT-4125: Regexes hurt my head!

Updated the regex to match a free URL in plain text with no http:
protocol. This now explicitly does not match e-mail addresses, such as
test@lindenlab.com (yay negative lookbehind regexes). It additionally
matches URLs with a port or path after it, e.g., secondlife.com/status.

I've added a bunch more unit tests to asset positive and negative
matches for this regex, because no human can do this in their head.
parent 30a47979
No related branches found
No related tags found
No related merge requests found
......@@ -204,7 +204,7 @@ LLUrlEntryHTTPNoProtocol::LLUrlEntryHTTPNoProtocol()
mPattern = boost::regex("("
"\\bwww\\.\\S+\\.\\S+" // i.e. www.FOO.BAR
"|" // or
"\\b[^ \\t\\n\\r\\f\\v:/]+\\.(?:com|net|edu|org)[^[:space:][:alnum:]]*\\>" // i.e. FOO.net
"(?<!@)\\b[^[:space:]:@/]+\\.(?:com|net|edu|org)([/:]\\S*)?\\b" // i.e. FOO.net
")",
boost::regex::perl|boost::regex::icase);
mMenuName = "menu_url_http.xml";
......
......@@ -571,6 +571,26 @@ namespace tut
"MIT web site is at web.mit.edu and also www.mit.edu",
"web.mit.edu");
testRegex("don't match e-mail addresses", r,
"test@lindenlab.com",
"");
testRegex(".com URL with path", r,
"see secondlife.com/status for grid status",
"secondlife.com/status");
testRegex(".com URL with port", r,
"secondlife.com:80",
"secondlife.com:80");
testRegex(".com URL with port and path", r,
"see secondlife.com:80/status",
"secondlife.com:80/status");
testRegex("www.*.com URL with port and path", r,
"see www.secondlife.com:80/status",
"www.secondlife.com:80/status");
testRegex("invalid .com URL [1]", r,
"..com",
"");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment