Skip to content

Commit

Permalink
Escape literal hyphens in regex character classes (fix #1206)
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent Racineux committed Oct 30, 2020
1 parent 5c92352 commit cd358aa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@ protected function _li($str) {
$type='ul';
// Main loop
while ($ptr<$len) {
if (preg_match('/^\h*[*-](?:\h?[*-]){2,}(?:\n+|$)/',
if (preg_match('/^\h*[*\-](?:\h?[*\-]){2,}(?:\n+|$)/',
substr($str,$ptr),$match)) {
$ptr+=strlen($match[0]);
// Embedded horizontal rule
return (strlen($dst)?
('<'.$type.'>'."\n".$dst.'</'.$type.'>'."\n\n"):'').
'<hr />'."\n\n".$this->build(substr($str,$ptr));
}
elseif (preg_match('/(?<=^|\n)([*+-]|\d+\.)\h'.
elseif (preg_match('/(?<=^|\n)([*+\-]|\d+\.)\h'.
'(.+?(?:\n+|$))((?:(?: {4}|\t)+.+?(?:\n+|$))*)/s',
substr($str,$ptr),$match)) {
$match[3]=preg_replace('/(?<=^|\n)(?: {4}|\t)/','',$match[3]);
Expand Down Expand Up @@ -466,10 +466,10 @@ protected function build($str) {
'pre'=>'/^(?:(?: {4}|\t).+?(?:\n+|$))+/',
'fence'=>'/^`{3}\h*(\w+)?.*?[^\n]*\n+(.+?)`{3}[^\n]*'.
'(?:\n+|$)/s',
'hr'=>'/^\h*[*_-](?:\h?[\*_-]){2,}\h*(?:\n+|$)/',
'hr'=>'/^\h*[*_\-](?:\h?[\*_\-]){2,}\h*(?:\n+|$)/',
'atx'=>'/^\h*(#{1,6})\h?(.+?)\h*(?:#.*)?(?:\n+|$)/',
'setext'=>'/^\h*(.+?)\h*\n([=-])+\h*(?:\n+|$)/',
'li'=>'/^(?:(?:[*+-]|\d+\.)\h.+?(?:\n+|$)'.
'setext'=>'/^\h*(.+?)\h*\n([=\-])+\h*(?:\n+|$)/',
'li'=>'/^(?:(?:[*+\-]|\d+\.)\h.+?(?:\n+|$)'.
'(?:(?: {4}|\t)+.+?(?:\n+|$))*)+/s',
'raw'=>'/^((?:<!--.+?-->|'.
'<(address|article|aside|audio|blockquote|canvas|dd|'.
Expand Down
2 changes: 1 addition & 1 deletion smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SMTP extends Magic {
**/
protected function fixheader($key) {
return str_replace(' ','-',
ucwords(preg_replace('/[_-]/',' ',strtolower($key))));
ucwords(preg_replace('/[_\-]/',' ',strtolower($key))));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion template.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function parse($text) {
// Build tree structure
for ($ptr=0,$w=5,$len=strlen($text),$tree=[],$tmp='';$ptr<$len;)
if (preg_match('/^(.{0,'.$w.'}?)<(\/?)(?:F3:)?'.
'('.$this->tags.')\b((?:\s+[\w.:@!-]+'.
'('.$this->tags.')\b((?:\s+[\w.:@!\-]+'.
'(?:\h*=\h*(?:"(?:.*?)"|\'(?:.*?)\'))?|'.
'\h*\{\{.+?\}\})*)\h*(\/?)>/is',
substr($text,$ptr),$match)) {
Expand Down

0 comments on commit cd358aa

Please sign in to comment.