Bug 635993 - Attachment reminder doesn't recognize file names with matching file-type extensions. r=bwinton

This commit is contained in:
Jason Yeo 2011-12-13 13:39:32 +00:00
Родитель 39682b2c87
Коммит 031a2a5f73
2 изменённых файлов: 38 добавлений и 23 удалений

Просмотреть файл

@ -88,15 +88,32 @@ function GetAttachmentKeywords(mailData,keywordsInCsv)
// If the keyword starts (ends) with a CJK character, we don't care
// what the previous (next) character is, because the words aren't
// space delimited.
var start = IsCJK(kw.charCodeAt(0)) ? "" : ("(^|" + NOT_W + ")");
var end = IsCJK(kw.charCodeAt(kw.length - 1)) ? "" : ("(" + NOT_W + "|$)");
var re = new RegExp(start + kw + end, "i");
var matching = re.exec(mailData);
// Ignore the match if it was a URL.
if (matching && !(/^http|^ftp/i.test(matching[0])))
// We're not worried about matching too much because we only add the
// keyword to the list of found keywords.
keywordsFound.push(keywordsArray[i]);
var re;
var matching;
var isFileType = kw.charAt(1) == ".";
var start;
var end;
if (isFileType) {
start = "(([^\\s]*)\\b)";
end = IsCJK(kw.charCodeAt(kw.length - 1)) ? "" : "(\\s|$)";
re = new RegExp(start + kw + end, "ig");
matching = mailData.match(re);
if (matching) {
var j, len;
for (j = 0, len = matching.length; j < len; j++) {
// Ignore the match if it was a URL.
if (!(/^(http|ftp|https):\/\//i.test(matching[j])))
keywordsFound.push(matching[j].trim());
}
}
} else {
start = IsCJK(kw.charCodeAt(0)) ? "" : ("(^|" + NOT_W + ")");
end = IsCJK(kw.charCodeAt(kw.length - 1)) ? "" : ("(" + NOT_W + "|$)");
re = new RegExp(start + kw + end, "i");
matching = re.exec(mailData);
if (matching)
keywordsFound.push(keywordsArray[i]);
}
}
return keywordsFound;
}

Просмотреть файл

@ -72,17 +72,6 @@ function utf8_decode(s)
* TESTS
*/
/**
* Test the GetAttachmentKeywords method with a simple word.
*/
function test_GetAttachmentKeywords_simple()
{
let mailData = utf8_decode("latte.ca");
let keywords = utf8_decode("latte");
let result = GetAttachmentKeywords(mailData, keywords);
assert_equal(result, "latte", "Simple keyword not equal!");
}
function test_GetAttachmentKeywords(desc, mailData, keywords, expected)
{
mailData = utf8_decode(mailData);
@ -93,10 +82,13 @@ function test_GetAttachmentKeywords(desc, mailData, keywords, expected)
}
var tests = [
// This is a function to demonstrate that we can put functions here.
test_GetAttachmentKeywords_simple,
// Desc, mail body Data, keywords to search for, expected keywords found.
["Simple keyword", "latte.ca", "latte", "latte"],
["Extension", "testing document.pdf", ".pdf", "document.pdf"],
["Two Extensions", "testing document.pdf and test.pdf", ".pdf",
"document.pdf,test.pdf"],
["Url", "testing http://document.pdf", ".pdf", ""],
["Both", "testing http://document.pdf test.pdf", ".pdf", "test.pdf"],
["Greek", "This is a Θεωρία test", "Θεωρία,is", "Θεωρία,is"],
["Greek missing", "This a Θεωρίαω test", "Θεωρία", ""],
["Greek and punctuation", "This a:Θεωρία-test", "Θεωρία", "Θεωρία"],
@ -108,6 +100,12 @@ var tests = [
["Japanese and English Mixed missing", "添付mailing", "添付mail", ""],
["Japanese trailers", "This is 添添付付! test", "Θεωρία,添付", "添付"],
["Multi-lang", "cv添付Θεωρία", "Θεωρία,添付,cv", "Θεωρία,添付,cv"],
["Should match", "I've attached the http/test.pdf file", ".pdf",
"http/test.pdf"],
["Should still fail", "a https://test.pdf a", ".pdf", ""],
["Should match Japanese", "a test.添付 a", ".添付", "test.添付"],
["Should match Greek", "a test.Θεωρία a", ".Θεωρία", "test.Θεωρία"],
["Should match once", "a test.pdf.doc a", ".pdf,.doc", "test.pdf.doc"],
];
function run_test()