@@ -127,7 +127,7 @@ public function iterateByCharacters($characters, $callback, Delimiter $stackBott
127127 $ characters = [$ characters ];
128128 }
129129
130- $ potentialOpeners = array_fill_keys ($ characters , $ stackBottom );
130+ $ openersBottom = array_fill_keys ($ characters , $ stackBottom );
131131
132132 // Find first closer above stackBottom
133133 $ closer = $ this ->findEarliest ($ stackBottom );
@@ -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 , $ stackBottom );
139+ $ opener = $ this ->findFirstMatchingOpener ($ closer , $ openersBottom , $ stackBottom );
140140
141141 $ oldCloser = $ closer ;
142142
@@ -145,7 +145,7 @@ public function iterateByCharacters($characters, $callback, Delimiter $stackBott
145145 } else {
146146 $ closer = $ closer ->getNext ();
147147 // Set lower bound for future searches for openers:
148- $ potentialOpeners [$ closerChar ] = $ closer ;
148+ $ openersBottom [$ closerChar ] = $ oldCloser -> getPrevious () ;
149149 if (!$ oldCloser ->canOpen ()) {
150150 // We can remove a closer that can't be an opener,
151151 // once we've seen there's no matching opener:
@@ -160,17 +160,17 @@ public function iterateByCharacters($characters, $callback, Delimiter $stackBott
160160
161161 /**
162162 * @param Delimiter $closer
163- * @param array $potentialOpeners
163+ * @param array $openersBottom
164164 * @param Delimiter|null $stackBottom
165165 *
166166 * @return Delimiter|null
167167 */
168- protected function findFirstMatchingOpener (Delimiter $ closer , $ potentialOpeners , Delimiter $ stackBottom = null )
168+ protected function findFirstMatchingOpener (Delimiter $ closer , $ openersBottom , Delimiter $ stackBottom = null )
169169 {
170170 $ closerChar = $ closer ->getChar ();
171171 $ opener = $ closer ->getPrevious ();
172172
173- while ($ opener !== null && $ opener !== $ stackBottom && $ opener !== $ potentialOpeners [$ closerChar ]) {
173+ while ($ opener !== null && $ opener !== $ stackBottom && $ opener !== $ openersBottom [$ closerChar ]) {
174174 if ($ opener ->getChar () === $ closerChar && $ opener ->canOpen ()) {
175175 return $ opener ;
176176 }
0 commit comments