fixed wrongly parsing link with @ symbol as username

This commit is contained in:
Tony Yang 2019-06-29 23:57:44 +08:00
parent 787c58906e
commit ef220fe537
Signed by: t510599
GPG Key ID: D88388851C28715D
2 changed files with 6 additions and 2 deletions

View File

@ -12,9 +12,11 @@ function postProcess(...callbacks) {
function linkSanitize() { function linkSanitize() {
$('.markdown-body a').each((_i, e) => { $('.markdown-body a').each((_i, e) => {
href = (e.getAttribute('href')) ? _.unescape(e.getAttribute('href').toLowerCase()) : ""; href = (e.href) ? _.unescape(e.href.toLowerCase()) : "";
if (href.indexOf('javascript:') != -1) { if (href.indexOf('javascript:') != -1) {
e.setAttribute('href', '#'); e.href = '#';
} else {
e.href = e.href.replace(/%40/, '@');
} }
}); });
} }

View File

@ -9,10 +9,12 @@ function parse_user_tag($markdown) {
$regex = array( $regex = array(
"code_block" => "/(`{1,3}[^`]*`{1,3})/", "code_block" => "/(`{1,3}[^`]*`{1,3})/",
"email" => "/[^@\s]*@[^@\s]*\.[^@\s]*/", "email" => "/[^@\s]*@[^@\s]*\.[^@\s]*/",
"url" => "/https?\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]+(\/\S*)/",
"username" => "/@(\w+)/" "username" => "/@(\w+)/"
); );
$tmp = preg_replace($regex["code_block"], " ", $markdown); $tmp = preg_replace($regex["code_block"], " ", $markdown);
$tmp = preg_replace($regex['url'], " ", $tmp);
$tmp = preg_replace($regex["email"], " ", $tmp); $tmp = preg_replace($regex["email"], " ", $tmp);
preg_match_all($regex["username"], $tmp, $username_list); preg_match_all($regex["username"], $tmp, $username_list);