Skip to content

Commit e608731

Browse files
committed
Fix emphasis/link parsing bug (commonmark/commonmark.js#50)
1 parent 8180880 commit e608731

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Delimiter/DelimiterStack.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function iterateByCharacters($characters, $callback, Delimiter $stackBott
136136
$closerChar = $closer->getChar();
137137
if ($closer->canClose() && (in_array($closerChar, $characters))) {
138138
// Found emphasis closer. Now look back for first matching opener:
139-
$opener = $this->findFirstMatchingOpener($closer, $potentialOpeners);
139+
$opener = $this->findFirstMatchingOpener($closer, $potentialOpeners, $stackBottom);
140140

141141
$oldCloser = $closer;
142142

@@ -159,17 +159,18 @@ public function iterateByCharacters($characters, $callback, Delimiter $stackBott
159159
}
160160

161161
/**
162-
* @param Delimiter $closer
163-
* @param array $potentialOpeners
162+
* @param Delimiter $closer
163+
* @param array $potentialOpeners
164+
* @param Delimiter|null $stackBottom
164165
*
165166
* @return Delimiter|null
166167
*/
167-
protected function findFirstMatchingOpener(Delimiter $closer, $potentialOpeners)
168+
protected function findFirstMatchingOpener(Delimiter $closer, $potentialOpeners, Delimiter $stackBottom = null)
168169
{
169170
$closerChar = $closer->getChar();
170171
$opener = $closer->getPrevious();
171172

172-
while ($opener !== null && $opener !== $potentialOpeners[$closerChar]) {
173+
while ($opener !== null && $opener !== $stackBottom && $opener !== $potentialOpeners[$closerChar]) {
173174
if ($opener->getChar() === $closerChar && $opener->canOpen()) {
174175
return $opener;
175176
}

0 commit comments

Comments
 (0)