Bug 1509493 - Fix markup generation for nested email addresses r=BenB

In mozTXTToHTMLConv, FindURL is not able to correctly calculate replaceBefore for nested email addresses/URLs such as john@doe.org}john@doe.org. As a workaround, we keep track of the end of the last URL HTML markup in the output string and skip any subsequent URLs whose replaceBefore would cut into this markup.

Differential Revision: https://phabricator.services.mozilla.com/D13391

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Fabian Henneke 2018-11-29 15:49:29 +00:00
Родитель a898f276d0
Коммит 51d3d2f9c6
2 изменённых файлов: 27 добавлений и 0 удалений

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

@ -1086,6 +1086,8 @@ mozTXTToHTMLConv::ScanTXT(const char16_t * aInString, int32_t aInStringLength, u
uint32_t structPhrase_italic = 0;
uint32_t structPhrase_code = 0;
uint32_t endOfLastURLOutput = 0;
nsAutoString outputHTML; // moved here for performance increase
for(uint32_t i = 0; int32_t(i) < aInStringLength;)
@ -1173,8 +1175,13 @@ mozTXTToHTMLConv::ScanTXT(const char16_t * aInString, int32_t aInStringLength, u
structPhrase_underline + structPhrase_code == 0
/* workaround for bug #19445 */ )
{
// Don't cut into previously inserted HTML (bug 1509493)
if (aOutString.Length() - replaceBefore < endOfLastURLOutput) {
break;
}
aOutString.Cut(aOutString.Length() - replaceBefore, replaceBefore);
aOutString += outputHTML;
endOfLastURLOutput = aOutString.Length();
i += replaceAfter + 1;
continue;
}

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

@ -148,6 +148,16 @@ function run_test() {
{
input: "test http://www.map.com/map.php?t=Nova_Scotia&markers=//Not_a_survey||description=plm2 test",
url: "http://www.map.com/map.php?t=Nova_Scotia&amp;markers=//Not_a_survey||description=plm2"
},
{
input: "bug#1509493 (john@mozilla.org)john@mozilla.org test",
url: "mailto:john@mozilla.org",
text: "john@mozilla.org"
},
{
input: "bug#1509493 {john@mozilla.org}john@mozilla.org test",
url: "mailto:john@mozilla.org",
text: "john@mozilla.org"
}
];
@ -210,13 +220,23 @@ function run_test() {
return ' href="' + url + '"';
}
function linkText(plaintext) {
return '>' + plaintext + '</a>';
}
for (let i = 0; i < scanTXTtests.length; i++) {
let t = scanTXTtests[i];
let output = converter.scanTXT(t.input, Ci.mozITXTToHTMLConv.kURLs);
let link = hrefLink(t.url);
let text;
if (t.text)
text = linkText(t.text);
if (!output.includes(link))
do_throw("Unexpected conversion by scanTXT: input=" + t.input +
", output=" + output + ", link=" + link);
if (text && !output.includes(text))
do_throw("Unexpected conversion by scanTXT: input=" + t.input +
", output=" + output + ", text=" + text);
}
for (let i = 0; i < scanHTMLtests.length; i++) {