jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/327879 )

Change subject: Escape cite ids with Sanitizer.escapeId
......................................................................


Escape cite ids with Sanitizer.escapeId

* Without this, refs like <ref name=":0"> won't generate the same
  links that the PHP parser generates.

* Updated an existing test to add the :0 key that require escapeId
  to be encoded properly.

Change-Id: I69e5f16ccf64bd1c9cf05bdea7a379e679d36b1a
---
M lib/ext/Cite/index.js
M tests/parserTests.txt
2 files changed, 8 insertions(+), 11 deletions(-)

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



diff --git a/lib/ext/Cite/index.js b/lib/ext/Cite/index.js
index eabfc17..1379725 100644
--- a/lib/ext/Cite/index.js
+++ b/lib/ext/Cite/index.js
@@ -4,13 +4,12 @@
  * ---------------------------------------------------------------------- */
 'use strict';
 
-var entities = module.parent.require('entities');
-
 var ParsoidExtApi = 
module.parent.require('./extapi.js').versionCheck('^0.6.1');
 var Util = ParsoidExtApi.Util;
 var DU = ParsoidExtApi.DOMUtils;
 var Promise = ParsoidExtApi.Promise;
 var defines = ParsoidExtApi.defines;
+var Sanitizer = module.parent.require('../wt2html/tt/Sanitizer.js').Sanitizer;
 
 // define some constructor shortcuts
 var KV = defines.KV;
@@ -172,10 +171,8 @@
        // Looks like Cite.php doesn't try to fix ids that already have
        // a "_" in them. Ex: name="a b" and name="a_b" are considered
        // identical. Not sure if this is a feature or a bug.
-       // It also considers entities equal to their encoding (i.e. '&' === 
'&amp;')
-       // and then substitutes % with .
-       var v = entities.decodeHTML(val).replace(/\s/g, '_');
-       return encodeURIComponent(v).replace(/%/g, ".");
+       // It also considers entities equal to their encoding (i.e. '&' === 
'&amp;').
+       return Sanitizer.escapeId(val, { noninitial: true });
 }
 
 RefGroup.prototype.renderLine = function(env, refsList, ref) {
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index 4ae2c0e..7703d28 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -22672,15 +22672,15 @@
 Ref: 17. Generate valid HTML5 id/about attributes
 !!wikitext
 <ref name="a b">foo</ref>
+<ref name=":0">ve-created name</ref>
 
 <references />
 !!html/parsoid
-<p><span class="mw-ref" id="cite_ref-a_b_1-0" rel="dc:references" 
typeof="mw:Extension/ref" 
data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-a_b-1"},"attrs":{"name":"a
 b"}}'><a href="./Main_Page#cite_note-a_b-1"><span 
class="mw-reflink-text">[1]</span></a></span>
-</p>
+<p><span about="#mwt2" class="mw-ref" id="cite_ref-a_b_1-0" 
rel="dc:references" typeof="mw:Extension/ref" 
data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-a_b-1"},"attrs":{"name":"a
 b"}}'><a href="./Main_Page#cite_note-a_b-1" style="counter-reset: mw-Ref 
1;"><span class="mw-reflink-text">[1]</span></a></span>
+<span about="#mwt4" class="mw-ref" id="cite_ref-:0_2-0" rel="dc:references" 
typeof="mw:Extension/ref" 
data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-:0-2"},"attrs":{"name":":0"}}'><a
 href="./Main_Page#cite_note-:0-2" style="counter-reset: mw-Ref 2;"><span 
class="mw-reflink-text">[2]</span></a></span>
 
-<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" 
data-mw='{"name":"references","attrs":{}}'>
-<li about="#cite_note-a_b-1" id="cite_note-a_b-1"><a 
href="./Main_Page#cite_ref-a_b_1-0" rel="mw:referencedBy"><span 
class="mw-linkback-text">↑ </span></a> <span 
id="mw-reference-text-cite_note-a_b-1" class="mw-reference-text">foo</span></li>
-</ol>
+<ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" 
data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-a_b-1" 
id="cite_note-a_b-1"><a href="./Main_Page#cite_ref-a_b_1-0" 
rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span 
id="mw-reference-text-cite_note-a_b-1" 
class="mw-reference-text">foo</span></li><li about="#cite_note-:0-2" 
id="cite_note-:0-2"><a href="./Main_Page#cite_ref-:0_2-0" 
rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span 
id="mw-reference-text-cite_note-:0-2" class="mw-reference-text">ve-created 
name</span></li></ol>
+
 !!end
 
 !!test

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I69e5f16ccf64bd1c9cf05bdea7a379e679d36b1a
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <ssas...@wikimedia.org>
Gerrit-Reviewer: Arlolra <abrea...@wikimedia.org>
Gerrit-Reviewer: C. Scott Ananian <canan...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to