MAINT-5019 FIXED Undesired "http://" added to domains sent in chat

Completely removed matching of the URLs w/o a protocol
+ Some unit tests
master
AndreyL ProductEngine 2015-07-29 07:35:08 +03:00
parent 33dfd860ec
commit e62d5ea4e8
5 changed files with 68 additions and 130 deletions

View File

@ -2064,7 +2064,7 @@ void LLTextBase::appendTextImpl(const std::string &new_text, const LLStyle::Para
// output the styled Url
appendAndHighlightTextImpl(match.getLabel(), part, link_params, match.underlineOnHoverOnly());
// show query part of url with gray color only for LLUrlEntryHTTP and LLUrlEntryHTTPNoProtocol url entries
// show query part of url with gray color only for LLUrlEntryHTTP url entries
std::string label = match.getQuery();
if (label.size())
{

View File

@ -287,42 +287,6 @@ std::string LLUrlEntryHTTPLabel::getUrl(const std::string &string) const
return getUrlFromWikiLink(string);
}
//
// LLUrlEntryHTTPNoProtocol Describes generic Urls like www.google.com
//
LLUrlEntryHTTPNoProtocol::LLUrlEntryHTTPNoProtocol()
: LLUrlEntryBase()
{
mPattern = boost::regex("\\bwww\\.\\S+\\.([^\\s<]*)?\\b", // i.e. www.FOO.BAR
boost::regex::perl|boost::regex::icase);
mMenuName = "menu_url_http.xml";
mTooltip = LLTrans::getString("TooltipHttpUrl");
}
std::string LLUrlEntryHTTPNoProtocol::getLabel(const std::string &url, const LLUrlLabelCallback &cb)
{
return urlToLabelWithGreyQuery(url);
}
std::string LLUrlEntryHTTPNoProtocol::getQuery(const std::string &url) const
{
return urlToGreyQuery(url);
}
std::string LLUrlEntryHTTPNoProtocol::getUrl(const std::string &string) const
{
if (string.find("://") == std::string::npos)
{
return "http://" + escapeUrl(string);
}
return escapeUrl(string);
}
std::string LLUrlEntryHTTPNoProtocol::getTooltip(const std::string &url) const
{
return unescapeUrl(url);
}
LLUrlEntryInvalidSLURL::LLUrlEntryInvalidSLURL()
: LLUrlEntryBase()
{
@ -485,7 +449,7 @@ std::string LLUrlEntrySLURL::getLocation(const std::string &url) const
//
LLUrlEntrySecondlifeURL::LLUrlEntrySecondlifeURL()
{
mPattern = boost::regex("(https?://)?([-\\w\\.]*\\.)?(secondlife|lindenlab)\\.com(:\\d{1,5})?\\/\\S*",
mPattern = boost::regex("https?://([-\\w\\.]*\\.)?(secondlife|lindenlab)\\.com(:\\d{1,5})?\\/\\S*",
boost::regex::perl|boost::regex::icase);
mIcon = "Hand";
@ -523,7 +487,7 @@ std::string LLUrlEntrySecondlifeURL::getTooltip(const std::string &url) const
//
LLUrlEntrySimpleSecondlifeURL::LLUrlEntrySimpleSecondlifeURL()
{
mPattern = boost::regex("(https?://)?([-\\w\\.]*\\.)?(secondlife|lindenlab)\\.com(?!\\S)",
mPattern = boost::regex("https?://([-\\w\\.]*\\.)?(secondlife|lindenlab)\\.com(?!\\S)",
boost::regex::perl|boost::regex::icase);
mIcon = "Hand";

View File

@ -157,19 +157,6 @@ public:
/*virtual*/ std::string getUrl(const std::string &string) const;
};
///
/// LLUrlEntryHTTPNoProtocol Describes generic Urls like www.google.com
///
class LLUrlEntryHTTPNoProtocol : public LLUrlEntryBase
{
public:
LLUrlEntryHTTPNoProtocol();
/*virtual*/ std::string getLabel(const std::string &url, const LLUrlLabelCallback &cb);
/*virtual*/ std::string getQuery(const std::string &url) const;
/*virtual*/ std::string getUrl(const std::string &string) const;
/*virtual*/ std::string getTooltip(const std::string &url) const;
};
class LLUrlEntryInvalidSLURL : public LLUrlEntryBase
{
public:

View File

@ -76,9 +76,6 @@ LLUrlRegistry::LLUrlRegistry()
registerUrl(new LLUrlEntrySL());
mUrlEntrySLLabel = new LLUrlEntrySLLabel();
registerUrl(mUrlEntrySLLabel);
// most common pattern is a URL without any protocol starting with "www",
// e.g., "www.secondlife.com"
registerUrl(new LLUrlEntryHTTPNoProtocol());
registerUrl(new LLUrlEntryEmail());
}

View File

@ -651,79 +651,6 @@ namespace tut
template<> template<>
void object::test<11>()
{
//
// test LLUrlEntryHTTPNoProtocol - general URLs without a protocol, starting with "www." prefix (MAINT-5019)
//
LLUrlEntryHTTPNoProtocol url;
testRegex("naked .com URL", url,
"see google.com",
"");
testRegex("naked .org URL", url,
"see en.wikipedia.org for details",
"");
testRegex("naked .net URL", url,
"example.net",
"");
testRegex("naked .edu URL (2 instances), .www prefix", url,
"MIT web site is at web.mit.edu and also www.mit.edu",
"http://www.mit.edu");
testRegex("don't match e-mail addresses", url,
"test@lindenlab.com",
"");
testRegex("www.test.com URL with path", url,
"see www.test.com/status for grid status",
"http://www.test.com/status");
testRegex("www.test.com URL with port", url,
"www.test.com:80",
"http://www.test.com:80");
testRegex("www.test.com URL with port and path", url,
"see www.test.com:80/status",
"http://www.test.com:80/status");
testRegex("www.*.com URL with port and path", url,
"see www.test.com:80/status",
"http://www.test.com:80/status");
testRegex("invalid .com URL [1]", url,
"..com",
"");
testRegex("invalid .com URL [2]", url,
"you.come",
"");
testRegex("invalid .com URL [3]", url,
"recommended",
"");
testRegex("invalid .edu URL", url,
"hi there scheduled maitenance has begun",
"");
testRegex("invalid .net URL", url,
"foo.netty",
"");
testRegex("XML tags around URL [1]", url,
"<foo>www.test.com</foo>",
"http://www.test.com");
testRegex("XML tags around URL [2]", url,
"<foo>www.test.com/status?bar=1</foo>",
"http://www.test.com/status?bar=1");
}
template<> template<>
void object::test<12>()
{
//
// test LLUrlEntryNoLink - turn off hyperlinking
@ -752,7 +679,7 @@ namespace tut
}
template<> template<>
void object::test<13>()
void object::test<12>()
{
//
// test LLUrlEntryRegion - secondlife:///app/region/<location> URLs
@ -862,7 +789,7 @@ namespace tut
}
template<> template<>
void object::test<14>()
void object::test<13>()
{
//
// test LLUrlEntryemail - general emails
@ -894,4 +821,67 @@ namespace tut
"test@ foo.com",
"");
}
template<> template<>
void object::test<14>()
{
//
// test LLUrlEntrySimpleSecondlifeURL - http://*.secondlife.com/* and http://*lindenlab.com/* urls
//
LLUrlEntrySecondlifeURL url;
testRegex("match urls with protocol", url,
"this url should match http://lindenlab.com/products/second-life",
"http://lindenlab.com/products/second-life");
testRegex("match urls with protocol", url,
"search something https://marketplace.secondlife.com/products/search on marketplace and test the https",
"https://marketplace.secondlife.com/products/search");
testRegex("match urls with port", url,
"let's specify some port http://secondlife.com:888/status",
"http://secondlife.com:888/status");
testRegex("don't match urls w/o protocol", url,
"looks like an url something www.marketplace.secondlife.com/products but no https prefix",
"");
testRegex("but with a protocol www is fine", url,
"so let's add a protocol http://www.marketplace.secondlife.com:8888/products",
"http://www.marketplace.secondlife.com:8888/products");
testRegex("don't match urls w/o protocol", url,
"and even no www something secondlife.com/status",
"");
}
template<> template<>
void object::test<15>()
{
//
// test LLUrlEntrySimpleSecondlifeURL - http://*.secondlife.com and http://*lindenlab.com urls
//
LLUrlEntrySimpleSecondlifeURL url;
testRegex("match urls with a protocol", url,
"this url should match http://lindenlab.com",
"http://lindenlab.com");
testRegex("match urls with a protocol", url,
"search something https://marketplace.secondlife.com on marketplace and test the https",
"https://marketplace.secondlife.com");
testRegex("don't match urls w/o protocol", url,
"looks like an url something www.marketplace.secondlife.com but no https prefix",
"");
testRegex("but with a protocol www is fine", url,
"so let's add a protocol http://www.marketplace.secondlife.com",
"http://www.marketplace.secondlife.com");
testRegex("don't match urls w/o protocol", url,
"and even no www something lindenlab.com",
"");
}
}