TF-1162 Got the open link bug again
This commit is contained in:
@@ -21,11 +21,16 @@ class LinkifyHtml {
|
|||||||
final regexLinkWithHttp = _generateRegExp(r'(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])');
|
final regexLinkWithHttp = _generateRegExp(r'(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])');
|
||||||
final newReplacedTextWithHttp = replacedText.replaceAllMapped(regexLinkWithHttp, (regexMatch) {
|
final newReplacedTextWithHttp = replacedText.replaceAllMapped(regexLinkWithHttp, (regexMatch) {
|
||||||
final link = regexMatch.group(1);
|
final link = regexMatch.group(1);
|
||||||
final newLinkWithHttp = link?.isNotEmpty == true
|
log('LinkifyHtml::_linkifyUrlAddress():link: $link');
|
||||||
? '<a href="$link" target="_blank">$link</a>'
|
if (link?.isNotEmpty == true) {
|
||||||
: '';
|
if (replacedText.contains('<a href="$link"')) {
|
||||||
log('ConvertUrlStringToHtmlLinksTransformers::_linkifyUrlAddress(): newLinkWithHttp: $newLinkWithHttp');
|
return link!;
|
||||||
return newLinkWithHttp;
|
} else {
|
||||||
|
return '<a href="$link" target="_blank">$link</a>';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
replacedText = newReplacedTextWithHttp;
|
replacedText = newReplacedTextWithHttp;
|
||||||
|
|
||||||
@@ -35,11 +40,16 @@ class LinkifyHtml {
|
|||||||
final previousChar = regexMatch.group(1);
|
final previousChar = regexMatch.group(1);
|
||||||
log('LinkifyHtml::_linkifyUrlAddress(): previousChar: $previousChar');
|
log('LinkifyHtml::_linkifyUrlAddress(): previousChar: $previousChar');
|
||||||
final link = regexMatch.group(2);
|
final link = regexMatch.group(2);
|
||||||
final newLinkWithWWW = link?.isNotEmpty == true
|
log('LinkifyHtml::_linkifyUrlAddress():link: $link');
|
||||||
? '$previousChar<a href="https://$link" target="_blank">$link</a>'
|
if (link?.isNotEmpty == true) {
|
||||||
: '';
|
if (replacedText.contains('<a href="https://$link"') || replacedText.contains('<a href="http://$link"')) {
|
||||||
log('ConvertUrlStringToHtmlLinksTransformers::_linkifyUrlAddress(): newLinkWithWWW: $newLinkWithWWW');
|
return link!;
|
||||||
return newLinkWithWWW;
|
} else {
|
||||||
|
return '$previousChar<a href="https://$link" target="_blank">$link</a>';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
replacedText = newReplacedTextWithWWW;
|
replacedText = newReplacedTextWithWWW;
|
||||||
|
|
||||||
@@ -52,11 +62,15 @@ class LinkifyHtml {
|
|||||||
|
|
||||||
final newReplacedTextWitMailTo = inputText.replaceAllMapped(regexMailTo, (regexMatch) {
|
final newReplacedTextWitMailTo = inputText.replaceAllMapped(regexMailTo, (regexMatch) {
|
||||||
final emailAddress = regexMatch.group(1);
|
final emailAddress = regexMatch.group(1);
|
||||||
final newMailToLink = emailAddress?.isNotEmpty == true
|
if (emailAddress?.isNotEmpty == true) {
|
||||||
? '<a href="mailto:$emailAddress">$emailAddress</a>'
|
if (inputText.contains('<a href="mailto:$emailAddress"')) {
|
||||||
: '';
|
return emailAddress!;
|
||||||
log('ConvertUrlStringToHtmlLinksTransformers::_linkifyUrlAddress(): newMailToLink: $newMailToLink');
|
} else {
|
||||||
return newMailToLink;
|
return '<a href="mailto:$emailAddress">$emailAddress</a>';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return newReplacedTextWitMailTo;
|
return newReplacedTextWitMailTo;
|
||||||
|
|||||||
@@ -42,5 +42,18 @@ void main() {
|
|||||||
equals('See <a href="mailto:tdvu@linagora.com">tdvu@linagora.com</a> at Hanoi'));
|
equals('See <a href="mailto:tdvu@linagora.com">tdvu@linagora.com</a> at Hanoi'));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'generateLinkify should preserve the text when input text contain <a href=',
|
||||||
|
() async {
|
||||||
|
final htmlValidate = linkifyHtml.generateLinkify(
|
||||||
|
'Check console output at "<a href="https://ci-builds.apache.org/job/james/job/ApacheJames/job/master/765/">james/ApacheJames/master [master] [765]</a>"'
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
htmlValidate,
|
||||||
|
equals('Check console output at "<a href="https://ci-builds.apache.org/job/james/job/ApacheJames/job/master/765/">james/ApacheJames/master [master] [765]</a>"')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user