Skip to content

Commit

Permalink
fix backslash
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqi committed Nov 30, 2020
1 parent d96587b commit 1774a7b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
22 changes: 2 additions & 20 deletions Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,25 +382,6 @@ public function parseInline($text, $whiteList = '', $clearHolders = true, $enabl
$self = $this;
$text = $this->call('beforeParseInline', $text);

// 处理``之外的\字符
preg_match_all('/`.+?`/', $text, $matches);
$delimiters = $matches[0];
$lineTextArray = preg_split('/`.+?`/', $text);
$lineTextArray = array_map(function ($str) {
return preg_replace_callback("/\\\+/", function ($matches) {
$str = $matches[0];
if (mb_strlen($str) % 2 > 0) {
return $str . '\\';
} else {
return $str;
}
}, $str);
}, $lineTextArray);
$text = '';
do {
$text .= array_shift($lineTextArray) . array_shift($delimiters);
} while ($lineTextArray);

// code
$text = preg_replace_callback(
"/(^|[^\\\])(`+)(.+?)\\2/",
Expand All @@ -427,9 +408,10 @@ function ($matches) use ($self) {
$text = preg_replace_callback(
"/\\\(.)/u",
function ($matches) use ($self) {
$prefix = preg_match("/^[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]$/", $matches[1]) ? '' : '\\';
$escaped = htmlspecialchars($matches[1]);
$escaped = str_replace('$', '$', $escaped);
return $self->makeHolder($escaped);
return $self->makeHolder($prefix . $escaped);
},
$text
);
Expand Down
4 changes: 2 additions & 2 deletions test/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ function test($title, $specs) {
],
'bugfix' => [
'escape' => [
"\\[系统盘]:\\\\Documents and Settings\\\\[用户名]\\\\Cookies",
"<p>\[系统盘]:\\Documents and Settings\\[用户名]\\Cookies</p>"
"\\[系统盘]:\\Documents and Settings\\\\[用户名]\\\\Cookies$\\lambda$",
"<p>[系统盘]:\\Documents and Settings\\[用户名]\\Cookies$\\lambda$</p>"
],

'table' => [
Expand Down

0 comments on commit 1774a7b

Please sign in to comment.