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.

Depends on D13645

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Fabian Henneke 2018-12-02 16:18:29 +00:00
parent 5574403ce0
commit 082be04eec
2 changed files with 27 additions and 0 deletions

View File

@ -949,6 +949,8 @@ mozTXTToHTMLConv::ScanTXT(const nsAString& aInString, uint32_t whattodo,
uint32_t structPhrase_italic = 0;
uint32_t structPhrase_code = 0;
uint32_t endOfLastURLOutput = 0;
nsAutoString outputHTML; // moved here for performance increase
const char16_t* rawInputString = aInString.BeginReading();
@ -1027,9 +1029,14 @@ mozTXTToHTMLConv::ScanTXT(const nsAString& aInString, uint32_t whattodo,
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;
}

View File

@ -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"
}
];
@ -271,13 +281,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 < scanTXTglyph.length; i++) {