@@ -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