if (aInString[pos] == '@')
{
// only pre-pend a mailto url if the string contains a .domain in it..
//i.e. we want to linkify johndoe@foo.com but not "let's meet @8pm"
nsDependentString inString(aInString, aInLength);
if (inString.FindChar('.', pos) != kNotFound) // if we have a '.' after the @ sign....
{
aOutString.AssignLiteral("mailto:");
aOutString += aInString;
}
}
This part of the code just checks if there is an '.' after the '@' sign and ignores a lot of other invalid cases of an email address.
Invalid Addresses
a@.
a@..
a@..f
a@....f
@.
@.com
@a.com
@a
@a.
@a..
@a...com
a@a.a..a
So we must add more conditions to the if-statement in line 199, the first one is to check if we have a '.' right after the '@', the second condition is to check if we have more than one consecutive '.' after the '@' sign, the third condition is to check if the address ends with '.', finally we must check if the address starts with the '@' sign.
So this is my modified code:
if (aInString[pos] == '@')
{
nsDependentString inString(aInString, aInLength);
if ( (inString.FindChar('.', pos) != kNotFound) &&
(inString.CharAt(pos+1) != '.') &&
(inString.Find("..", pos) == kNotFound) &&
(inString.CharAt(inString.length()-1) != '.')&&
(pos!=0))
{
aOutString.AssignLiteral("mailto:");
aOutString += aInString;
}
}
Unfortunately I didn’t test or patch it :( for a well known reason :D, so can some one test it for me ??
No comments:
Post a Comment