jenkins-bot has submitted this change and it was merged.

Change subject: Allow ISBNs which end with a lowercase `x`
......................................................................


Allow ISBNs which end with a lowercase `x`

The links to Special:BookSources need to be all uppercase, though.

Change-Id: I3ddb63dcd13972c578ad2787b72b3925534779ff
---
M lib/mediawiki.WikiConfig.js
M lib/pegTokenizer.pegjs.txt
M tests/parserTests.txt
3 files changed, 15 insertions(+), 5 deletions(-)

Approvals:
  Subramanya Sastry: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/mediawiki.WikiConfig.js b/lib/mediawiki.WikiConfig.js
index f1d03bd..144483d 100644
--- a/lib/mediawiki.WikiConfig.js
+++ b/lib/mediawiki.WikiConfig.js
@@ -626,7 +626,7 @@
 
 WikiConfig.prototype.ExtResourceSerializer = {
        'ISBN': function(hrefWT, href, content) {
-               if (hrefWT.join('') === content.replace(/[\- ]/g, '')) {
+               if (hrefWT.join('') === content.replace(/[\- ]/g, 
'').toUpperCase()) {
                        return content;
                } else {
                        href = href.replace(/^\.\//, ''); // strip "./" prefix
@@ -654,7 +654,7 @@
 
        keys.forEach(function(key) {
                var reOpts = WikiConfig.prototype.ExtResourceURLPatterns[key];
-               var re = Util.escapeRegExp(reOpts.re).replace('%s', 
'(\\w+)').replace('%d', '(\\d+)').replace('%isbn', '(\\d+X?)');
+               var re = Util.escapeRegExp(reOpts.re).replace('%s', 
'(\\w+)').replace('%d', '(\\d+)').replace('%isbn', '(\\d+[Xx]?)');
                patterns.push("^(?:" + (reOpts.prefix || "") + re + ")$");
        });
 
diff --git a/lib/pegTokenizer.pegjs.txt b/lib/pegTokenizer.pegjs.txt
index 25ca29b..a77056e 100644
--- a/lib/pegTokenizer.pegjs.txt
+++ b/lib/pegTokenizer.pegjs.txt
@@ -458,7 +458,7 @@
 {
     // TODO: round-trip non-decimals too!
     var isbn = [head, digits, tail].join('');
-    var isbncode = isbn.replace(/[^\dX]/g, '');
+    var isbncode = isbn.replace(/[^\dX]/ig, '');
 
     // ISBNs can only be 10 or 13 chars long
     if ([10, 13].indexOf(isbncode.length) === -1) {
@@ -468,7 +468,7 @@
 
     return [
         new SelfclosingTagTk('extlink', [
-           new KV('href', 'Special:BookSources/' + isbncode),
+           new KV('href', 'Special:BookSources/' + isbncode.toUpperCase()),
            new KV('mw:content', 'ISBN ' + isbn),
            new KV('typeof', 'mw:ExtLink/ISBN'),
         ],
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index df5f5cd..a912506 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -18109,21 +18109,31 @@
 <p>ISBN <a href="./Special:BookSources/1234567890" rel="mw:ExtLink" 
data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a></p>
 !! end
 
+# Uppercase X and lowercase x as well
 !! test
 ISBN with an X
 !! wikitext
 ISBN 3-462-04561-X
+ISBN 3-462-04561-x
 ISBN 080442957X
+ISBN 080442957x
 ISBN 978080442957X
+ISBN 978080442957x
 !! html/php
 <p><a href="/wiki/Special:BookSources/346204561X" class="internal 
mw-magiclink-isbn">ISBN 3-462-04561-X</a>
+<a href="/wiki/Special:BookSources/346204561X" class="internal 
mw-magiclink-isbn">ISBN 3-462-04561-x</a>
 <a href="/wiki/Special:BookSources/080442957X" class="internal 
mw-magiclink-isbn">ISBN 080442957X</a>
+<a href="/wiki/Special:BookSources/080442957X" class="internal 
mw-magiclink-isbn">ISBN 080442957x</a>
 <a href="/wiki/Special:BookSources/978080442957X" class="internal 
mw-magiclink-isbn">ISBN 978080442957X</a>
+<a href="/wiki/Special:BookSources/978080442957X" class="internal 
mw-magiclink-isbn">ISBN 978080442957x</a>
 </p>
 !! html/parsoid
 <p><a href="./Special:BookSources/346204561X" rel="mw:ExtLink" 
data-parsoid='{"stx":"magiclink"}'>ISBN 3-462-04561-X</a>
+<a href="./Special:BookSources/346204561X" rel="mw:ExtLink" 
data-parsoid='{"stx":"magiclink"}'>ISBN 3-462-04561-x</a>
 <a href="./Special:BookSources/080442957X" rel="mw:ExtLink" 
data-parsoid='{"stx":"magiclink"}'>ISBN 080442957X</a>
-<a href="./Special:BookSources/978080442957X" rel="mw:ExtLink" 
data-parsoid='{"stx":"magiclink"}'>ISBN 978080442957X</a></p>
+<a href="./Special:BookSources/080442957X" rel="mw:ExtLink" 
data-parsoid='{"stx":"magiclink"}'>ISBN 080442957x</a>
+<a href="./Special:BookSources/978080442957X" rel="mw:ExtLink" 
data-parsoid='{"stx":"magiclink"}'>ISBN 978080442957X</a>
+<a href="./Special:BookSources/978080442957X" rel="mw:ExtLink" 
data-parsoid='{"stx":"magiclink"}'>ISBN 978080442957x</a></p>
 !! end
 
 !! test

-- 
To view, visit https://gerrit.wikimedia.org/r/231178
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3ddb63dcd13972c578ad2787b72b3925534779ff
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to