diff --git a/Cite_body.php b/Cite_body.php index b40a12e77..79a8176e0 100644 --- a/Cite_body.php +++ b/Cite_body.php @@ -604,30 +604,39 @@ class Cite { if ( strval( $str ) !== '' ) { $this->mReferencesGroup = $group; - # Detect whether we were sent already rendered s - # Mostly a side effect of using #tag to call references + # Detect whether we were sent already rendered s. + # Mostly a side effect of using #tag to call references. + # The following assumes that the parsed s sent within + # the block were the most recent calls to + # . This assumption is true for all known use cases, + # but not strictly enforced by the parser. It is possible + # that some unusual combination of #tag, and + # conditional parser functions could be created that would + # lead to malformed references here. $count = substr_count( $str, Parser::MARKER_PREFIX . "-ref-" ); + $redoStack = array(); + + # Undo effects of calling while unaware of containing for ( $i = 1; $i <= $count; $i++ ) { if ( !$this->mRefCallStack ) { break; } - # The following assumes that the parsed s sent within - # the block were the most recent calls to - # . This assumption is true for all known use cases, - # but not strictly enforced by the parser. It is possible - # that some unusual combination of #tag, and - # conditional parser functions could be created that would - # lead to malformed references here. $call = array_pop( $this->mRefCallStack ); + $redoStack[] = $call; if ( $call !== false ) { list( $type, $ref_argv, $ref_str, $ref_key, $ref_group, $ref_index ) = $call; - - # Undo effects of calling while unaware of containing $this->rollbackRef( $type, $ref_key, $ref_group, $ref_index ); + } + } - # Rerun call now that mInReferences is set. + # Rerun call now that mInReferences is set. + for ( $i = count( $redoStack ) - 1; $i >= 0; $i-- ) { + $call = $redoStack[$i]; + if ( $call !== false ) { + list( $type, $ref_argv, $ref_str, + $ref_key, $ref_group, $ref_index ) = $call; $this->guardedRef( $ref_str, $ref_argv, $parser ); } } diff --git a/citeParserTests.txt b/citeParserTests.txt index 695378c04..189a3f1be 100644 --- a/citeParserTests.txt +++ b/citeParserTests.txt @@ -584,3 +584,21 @@ Multiple definition (mixed outside/inside) !! end + +!! test +Multiple definition (inside {{#tag:references}}) +!! input + +{{#tag:references| +abc +def +}} +!! result +

[1] +

+
    +
  1. abc Cite error: Invalid <ref> tag; name "a" defined multiple times with different content +
  2. +
+ +!! end