(bug 8110) Make magic ISBN linking stricter: only match ten-digit sequences
authorIlmari Karonen <vyznev@users.mediawiki.org>
Mon, 18 Dec 2006 01:12:19 +0000 (01:12 +0000)
committerIlmari Karonen <vyznev@users.mediawiki.org>
Mon, 18 Dec 2006 01:12:19 +0000 (01:12 +0000)
(plus optional ISBN-13 prefix) with no immediately following alphanumeric
character, disallow multiple consecutive internal redirects.  This required
fixing a number of broken parser tests that had used a too-short ISBN.

RELEASE-NOTES
includes/Parser.php
maintenance/parserTests.txt

index 83400e3..b3a9468 100644 (file)
@@ -338,6 +338,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   mysteriously otherwise (detection code copied from install-utils.inc)
 * (bug 8295) Change handling of <center> tags in doBlockLevels() to match that
   of <div>
+* (bug 8110) Make magic ISBN linking stricter: only match ten-digit sequences
+  (plus optional ISBN-13 prefix) with no immediately following alphanumeric
+  character, disallow multiple consecutive internal redirects
 
 == Languages updated ==
 
index 9a0331d..97a1f13 100644 (file)
@@ -1038,7 +1038,11 @@ class Parser
                            <a.*?</a> |                 # Skip link text
                            <.*?> |                     # Skip stuff inside HTML elements
                            (?:RFC|PMID)\s+([0-9]+) |   # RFC or PMID, capture number as m[1]
-                           ISBN\s+(\b[0-9Xx\ \-]+)     # ISBN, capture number as m[2]
+                           ISBN\s+(\b                  # ISBN, capture number as m[2]
+                                     (?: 97[89] [\ \-]? )?   # optional 13-digit ISBN prefix
+                                     (?: [0-9]  [\ \-]? ){9} # 9 digits with opt. delimiters
+                                     [0-9Xx]                 # check digit
+                                   \b)
                        )!x', array( &$this, 'magicLinkCallback' ), $text );
                wfProfileOut( __METHOD__ );
                return $text;
index a9c9db2..923f466 100644 (file)
@@ -2917,9 +2917,9 @@ Thumbnail image caption with a free URL
 !! test
 BUG 1887: A ISBN with a thumbnail
 !! input
-[[Image:foobar.jpg|thumb|ISBN 12354]]
+[[Image:foobar.jpg|thumb|ISBN 1235467890]]
 !! result
-<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/Image:Foobar.jpg" class="internal" title="ISBN 12354"><img src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" alt="ISBN 12354" width="180" height="20" longdesc="/wiki/Image:Foobar.jpg" class="thumbimage" /></a>  <div class="thumbcaption"><div class="magnify" style="float:right"><a href="/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/skins/common/images/magnify-clip.png" width="15" height="11" alt="Enlarge" /></a></div><a href="/index.php?title=Special:Booksources&amp;isbn=12354" class="internal">ISBN 12354</a></div></div></div>
+<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/Image:Foobar.jpg" class="internal" title="ISBN 1235467890"><img src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" alt="ISBN 1235467890" width="180" height="20" longdesc="/wiki/Image:Foobar.jpg" class="thumbimage" /></a>  <div class="thumbcaption"><div class="magnify" style="float:right"><a href="/wiki/Image:Foobar.jpg" class="internal" title="Enlarge"><img src="/skins/common/images/magnify-clip.png" width="15" height="11" alt="Enlarge" /></a></div><a href="/index.php?title=Special:Booksources&amp;isbn=1235467890" class="internal">ISBN 1235467890</a></div></div></div>
 
 !! end
 
@@ -5753,9 +5753,9 @@ __FORCETOC__
 !! test
 ISBN code coverage
 !! input
-ISBN  983&#x20;987
+ISBN  978-0-1234-56&#x20;789
 !! result
-<p><a href="/index.php?title=Special:Booksources&amp;isbn=983" class="internal">ISBN 983</a>&#x20;987
+<p><a href="/index.php?title=Special:Booksources&amp;isbn=9780123456" class="internal">ISBN 978-0-1234-56</a>&#x20;789
 </p>
 !! end
 
@@ -5770,12 +5770,10 @@ ISBN
 
 !! test
 Double ISBN
-!! options
-disabled # Disabled until Bug 6560 resolved
 !! input
-ISBN ISBN 1234
+ISBN ISBN 1234567890
 !! result
-<p>ISBN <a href="/wiki/index.php?title=Special:Booksources&amp;isbn=1234" class="internal">ISBN 1234</a>
+<p>ISBN <a href="/index.php?title=Special:Booksources&amp;isbn=1234567890" class="internal">ISBN 1234567890</a>
 </p>
 !! end
 
@@ -6099,6 +6097,35 @@ ISBN  foo
 !! end
 
 
+!! test
+ISBN length
+!! input
+ISBN 123456789
+
+ISBN 1234567890
+
+ISBN 12345678901
+!! result
+<p>ISBN 123456789
+</p><p><a href="/index.php?title=Special:Booksources&amp;isbn=1234567890" class="internal">ISBN 1234567890</a>
+</p><p>ISBN 12345678901
+</p>
+!! end
+
+
+!! test
+ISBN with trailing year (bug 8110)
+!! input
+ISBN 1-234-56789-0 - 2006
+
+ISBN 1 234 56789 0 - 2006
+!! result
+<p><a href="/index.php?title=Special:Booksources&amp;isbn=1234567890" class="internal">ISBN 1-234-56789-0</a> - 2006
+</p><p><a href="/index.php?title=Special:Booksources&amp;isbn=1234567890" class="internal">ISBN 1 234 56789 0</a> - 2006
+</p>
+!! end
+
+
 !! test
 Pages in namespace (Magic word disabled currently)
 !! input