diff --git a/Cite_body.php b/Cite_body.php index 9daf9217f..7ec21483d 100644 --- a/Cite_body.php +++ b/Cite_body.php @@ -235,8 +235,14 @@ class Cite { $this->mReferencesErrors[] = $this->error( 'cite_error_references_missing_key', $key ); } else { - # Assign the text to corresponding ref - $this->mRefs[$group][$key]['text'] = $str; + if ( isset( $this->mRefs[$group][$key]['text'] ) && $str !== $this->mRefs[$group][$key]['text'] ) { + // two refs with same key and different content + // add error message to the original ref + $this->mRefs[$group][$key]['text'] .= ' ' . $this->error( 'cite_error_references_duplicate_key', $key, 'noparse' ); + } else { + # Assign the text to corresponding ref + $this->mRefs[$group][$key]['text'] = $str; + } } } else { # called in has no content. diff --git a/citeParserTests.txt b/citeParserTests.txt index b16005961..695378c04 100644 --- a/citeParserTests.txt +++ b/citeParserTests.txt @@ -532,3 +532,55 @@ Page one.This ref is invalid. invalid names, e.g. too many

!! end + +!! test +Multiple definition (outside ) +!! input +abc +def + +!! result +

[1] +[1] +

+
    +
  1. 1.0 1.1 abc Cite error: Invalid <ref> tag; name "a" defined multiple times with different content +
  2. +
+ +!! end + +!! test +Multiple definition (inside ) +!! input + + +abc +def + +!! result +

[1] +

+
    +
  1. abc Cite error: Invalid <ref> tag; name "a" defined multiple times with different content +
  2. +
+ +!! end + +!! test +Multiple definition (mixed outside/inside) +!! input +abc + +def + +!! result +

[1] +

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