jenkins-bot has submitted this change and it was merged.
Change subject: Fixed incorrect initialization of nested-ref-collection-map
......................................................................
Fixed incorrect initialization of nested-ref-collection-map
* The initialization of nestedRefCollectionMap[references-id]
in handleReferences was the wrong place to initialize it since
on pages with multiple <references /> tags, the map can get
reset after a references tag is processed. So, for later
references tags, the entry for those will get cleared which
led to crashes.
Ex: es:Abderramán_I and couple others found in RT testing.
* This patch fixes the crasher.
* Added a new parser test with multiple references tags that
captures this scenario. Regenerated selser changes file.
Change-Id: I64402e77996486b099acda114f2e250258b0048e
---
M js/lib/ext.Cite.js
M js/tests/parserTests.txt
M js/tests/selser.changes.json
3 files changed, 31 insertions(+), 3 deletions(-)
Approvals:
Cscott: Looks good to me, approved
jenkins-bot: Verified
diff --git a/js/lib/ext.Cite.js b/js/lib/ext.Cite.js
index c7e6bab..d7deddc 100644
--- a/js/lib/ext.Cite.js
+++ b/js/lib/ext.Cite.js
@@ -304,7 +304,6 @@
// Assign an about id and intialize the nested refs html
var referencesId = manager.env.newAboutId();
- this.nestedRefsHTMLMap[referencesId] = ["\n"];
// Emit a marker mw:DOMFragment for the references
// token so that the dom post processor can generate
@@ -434,6 +433,10 @@
node.parentNode.insertBefore(span, node);
} else {
var referencesAboutId = node.getAttribute("references-id");
+ // Init
+ if (!this.nestedRefsHTMLMap[referencesAboutId]) {
+ this.nestedRefsHTMLMap[referencesAboutId] = ["\n"];
+ }
this.nestedRefsHTMLMap[referencesAboutId].push(span.outerHTML,
"\n");
}
@@ -463,7 +466,7 @@
if (body.length > 0) {
datamwBody = {
'extsrc': body,
- 'html': this.nestedRefsHTMLMap[about].join('')
+ 'html': (this.nestedRefsHTMLMap[about] ||
[]).join('')
};
}
diff --git a/js/tests/parserTests.txt b/js/tests/parserTests.txt
index 3f15406..461357e 100644
--- a/js/tests/parserTests.txt
+++ b/js/tests/parserTests.txt
@@ -15032,6 +15032,29 @@
<ol class="references" about="#mwt2" typeof="mw:Transclusion"
data-mw='{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"<references
/>"}},"i":0}'></ol>
!!end
+!! test
+References: 7. Multiple references tags (one without and one with nested refs)
should be correctly handled
+!! options
+parsoid
+!! input
+A <ref>foo bar for a</ref>
+B <ref name="b" />
+
+<references />
+
+<references>
+<ref name="b">foo</ref>
+</references>
+!! result
+<p>A <span about="#mwt2" class="reference"
data-mw='{"name":"ref","body":{"html":"foo bar for a"},"attrs":{}}'
id="cite_ref-1-0" rel="dc:references" typeof="mw:Extension/ref"><a
href="#cite_note-1">[1]</a></span>
+B <span about="#mwt4" class="reference"
data-mw='{"name":"ref","attrs":{"name":"b"}}' id="cite_ref-b-2-0"
rel="dc:references" typeof="mw:Extension/ref"><a
href="#cite_note-b-2">[2]</a></span></p>
+
+<ol class="references" typeof="mw:Extension/references" about="#mwt6"
data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1"
id="cite_note-1"><span rel="mw:referencedBy"><a
href="#cite_ref-1-0">↑</a></span> foo bar for a</li><li about="#cite_note-b-2"
id="cite_note-b-2"><span rel="mw:referencedBy"><a
href="#cite_ref-b-2-0">↑</a></span> </li></ol>
+
+<ol class="references" typeof="mw:Extension/references" about="#mwt8"
data-mw='{"name":"references","body":{"extsrc":"<ref
name=\"b\">foo</ref>","html":"\n<span about=\"#mwt10\" class=\"reference\"
data-mw=\"{&quot;name&quot;:&quot;ref&quot;,&quot;body&quot;:{&quot;html&quot;:&quot;foo&quot;},&quot;attrs&quot;:{&quot;name&quot;:&quot;b&quot;}}\"
rel=\"dc:references\" typeof=\"mw:Extension/ref\"><a
href=\"#cite_note-b-1\">[1]</a></span>\n"},"attrs":{}}'><li
about="#cite_note-b-1" id="cite_note-b-1"><span rel="mw:referencedBy">↑</span>
foo</li></ol>
+
+!! end
+
#### ----------------------------------------------------------------
#### The following section of tests are primarily to test
#### wikitext escaping capabilities of Parsoid. Given that
diff --git a/js/tests/selser.changes.json b/js/tests/selser.changes.json
index b264e7e..a5e7581 100644
--- a/js/tests/selser.changes.json
+++ b/js/tests/selser.changes.json
@@ -1069,6 +1069,7 @@
"References: 4. only referenced group should be cleared after processing
references":[[2,0,0,2,[4,0],2,0],[[4,0,0,0],2,0,3,0,0,0],[4,0,0,3,[2,0],2,0],[[0,0,3,0],0,0,0,1,2,0],[4,2,0,0,2,0,0],[2,0,0,2,0,2,0],[3,4,0,0,1,3,0],[1,3,0,0,4,0,0],[4,4,0,0,2,2,0],[4,4,0,2,4,0,0],[1,0,0,0,2,4,0],[1,0,0,0,1,0,0],[[4,0,4,0],3,0,2,2,0,0],[3,4,0,0,2,0,0],[4,2,0,4,1,4,0],[[4,0,0,0],0,0,4,3,0,0],[[2,0,3,0],3,0,3,1,2,0],[1,0,0,0,2,0,0],[3,0,0,3,[4,0],0,0],[1,0,0,2,0,2,0]],
"References: 5. ref tags in references should be processed while ignoring all
other
content":[[3,2,0],[4,3,0],[4,2,0],[0,4,0],[[0,0,4,0],2,0],[[0,0,4,0],0,0],[1,0,0],[[4,0,2,0],3,0],[2,0,0],[[0,0,4,0],3,0],[[0,0,2,0],3,0],[[0,0,3,0],0,0],[2,2,0],0,[[2,0,0,0],0,0],[1,3,0],[[4,0,0,0],3,0],[4,4,0],[3,4,0],[0,2,0]],
"References: 6. <references /> from a transclusion":[0],
+"References: 7. Multiple references tags (one without and one with nested
refs) should be correctly
handled":[[[0,0,3,0],0,0,0,0],[[2,0,0,0],0,0,0,0],[2,3,0,2,0],[[4,0,4,0],3,0,0,0],0,[0,0,0,4,0],[2,0,0,4,0],[[4,0,0,0],2,0,0,0],[4,0,0,0,0],[[3,0,0,0],0,0,2,0],[[3,0,0,0],0,0,0,0],[3,0,0,4,0],[4,0,0,4,0],[2,3,0,0,0],[[3,0,0,0],2,0,0,0],[0,0,0,3,0],[3,2,0,0,0],[[0,0,2,0],4,0,0,0],[4,0,0,3,0],[0,2,0,2,0]],
"Headings: 0.
Unnested":[[0,4,4,2,[2,[3],[4]]],[1,2,[[3],0,2,2,2],0,[0,[2],0]],[1,3,[1,0,0,0,1],4,3],[4,0,3,3,2],[[3],0,3,3,4],[[1],0,4,3,3],[2,0,2,0,3],[3,0,2,2,2],[[3],2,1,0,[0,1,[2]]],[[3],0,[[3],0,3,4,0],0,[0,[2],2]],[[[4]],2,2,0,4],[[4],3,2,3,[0,4,[4]]],[4,3,2,0,3],[[[3]],3,1,3,[4,[3],1]],[[[3]],0,[4,0,2,0,4],0,[4,4,[3]]],[1,4,3,0,[0,[4],[3]]],[4,2,[[2],4,0,3,[3]],2,1],[0,0,1,3,1],[[[4]],2,2,4,3],[[1],0,[0,0,4,2,0],0,[0,0,3]]],
"Headings: 1. Nested inside
html":[[0,2,4,2,3,0,0,4,[[3]],0,4],[4,3,4,0,0,0,[[3]],3,[1],4,[[4]]],[1,2,3,4,1,2,1,3,1,0,1],[3,3,[3],0,4,0,[[3]],3,[[4]],0,4],[1,0,[[3]],3,3,4,1,4,0,0,2],[2,4,[1],0,2,0,3,2,0,2,1],[0,0,4,0,1,4,2,4,[1],0,[1]],[2,0,4,0,[[3]],4,4,0,1,2,2],[4,4,4,0,2,0,3,0,4,0,3],[2,4,[1],0,0,2,[4],0,1,2,1],[1,3,[[4]],0,3,0,0,0,1,0,3],[[2],4,0,3,[[2]],0,3,0,0,0,1],[4,2,4,0,[1],3,3,0,3,0,[[2]]],[[[2]],0,[[2]],0,[[3]],4,3,0,3,0,[[2]]],[4,0,2,0,[[3]],0,4,0,2,3,[4]],[[4],0,3,2,[3],4,1,2,0,0,4],[[2],0,3,0,3,3,3,4,[[3]],0,4],[0,3,0,2,0,0,[1],0,2,2,[[2]]],[[3],3,3,0,0,0,2,4,[3],0,1],[1,2,0,0,[[2]],3,3,2,0,0,[[3]]]],
"Headings: 2. Outside heading nest on a single line
<h1>foo</h1>*bar":[[0,0,[2,0],0,3,3,2,0,2,0,[[2]]],[[4],4,1,2,4,0,1,0,2,3,0],[[2],2,[[3],0],0,3,2,[4],4,2,0,3],[0,3,[[4],0],3,[4],4,[3],0,[4],0,1],[1,0,1,0,2,2,0,0,2,0,[[2]]],[[3],0,2,2,0,2,[4],0,4,0,1],[0,4,[[2],2],0,[2],0,3,3,[4],2,1],[3,2,2,4,2,3,0,3,1,0,[1]],[2,4,1,0,[2],0,0,4,0,0,1],[0,2,4,2,0,0,2,0,1,3,3],[[3],0,4,0,[3],0,1,0,4,0,1],[2,2,[[3],4],0,3,3,4,0,[3],0,[1]],[4,3,[[2],2],0,4,3,[3],0,1,0,[[3]]],[1,3,[3,2],0,4,0,0,3,0,0,[2]],[1,2,[[3],4],3,[4],2,[3],0,0,2,[3]],[4,0,4,0,[4],0,3,2,2,4,[[2]]],[3,2,[0,2],3,2,3,4,0,0,3,3],[2,3,3,0,[2],0,1,0,0,0,1],[[4],2,[[2],0],0,1,0,[2],4,0,2,3],[[4],3,[[4],0],2,0,0,2,0,[4],4,2]],
@@ -1142,9 +1143,10 @@
"Empty TR followed by mixed-ws-comment line should RT
correctly":[[2],[[2,[[3,1],3,4,3]]],[[0,[2,2,2,0]]],[4],[[0,1]],[3],[[2,3]],[[0,[3,0,[2,[2,2,0]],2]]],[[0,[[0,[4,0]],0,[2,4],0]]],[[3,[[2,0],2,[0,4],4]]],[1],[[0,[[0,1],3,4,2]]],[[0,[1,0,[0,4],0]]],[[0,[1,0,3,0]]],[[0,[[0,3],0,[2,[3,2,0]],0]]],[[2,4]],[[3,4]],[[0,[2,0,[0,1],3]]],[[3,[4,3,3,2]]],[[0,[[3,[4,2]],4,4,2]]]],
"Multi-line image caption generated by templates with/without trailing
newlines":[[[0,3],0,0],[[0,[4,0,0,0,4,0]],0,[0,[0,0,0,0,3,0,3]]],[[0,[2,0,0,0,0,0]],0,[0,3]],[[0,[0,0,4,0,0,0]],0,[0,4]],[[0,[2,0,3,0,2,0]],3,[0,1]],[[0,3],0,[0,1]],[[0,3],3,[0,1]],[[0,[3,0,0,0,3,0]],0,[0,1]],[[0,4],2,[0,[0,0,3,0,0,0,4]]],[[0,[0,0,2,0,0,0]],0,[0,2]],[[0,2],0,[0,4]],[[0,2],0,[0,2]],[[0,3],3,[0,3]],[[0,[3,0,3,0,2,0]],4,[0,[4,0,3,0,3,0,0]]],[[0,1],0,[0,[4,0,2,0,4,0,4]]],[[0,[2,0,0,0,4,0]],0,[0,[0,0,4,0,3,0,3]]],[[0,4],2,[0,3]],[[0,1],0,[0,[2,0,2,0,4,0,0]]],[[0,4],0,[0,1]],[[0,1],3,[0,2]]],
"Improperly nested inline or quotes tags with whitespace in
between":[[[[0,2],2,0,1,2]],[3],[4],[1],[[0,1,2,[0,2],0]],[[3,[4],4,0,3]],[2],[[1,4,2,2,3]],[[[2,[4]],3,0,[0,4],0]],[[[3,1],4,3,2,1]],[[[3,2],0,0,[4,[3]],3]],[[[0,2],[3],0,3,0]],[[3,2,0,[4,1],3]],[[3,2,0,[3,2],4]],[[3,0,4,3,0]],[[4,0,2,3,3]],[[1,3,0,2,1]],[[3,4,4,0,2]],[[[0,3],[3],0,3,0]],[[[2,1],[3],3,[0,3],0]]],
+"Encapsulate protected attributes from
wt":[0,[[3]],[4],[2],[1],[[4]],[3],[[2]]],
"Image: Modifying size of an image":[],
"Image: New block level image should have \\n before and after":[],
"Lists: Add space after bullets":[],
"Parsoid: Serialize positional parameters with = in them as named
parameter":[],
"_numchanges": 20
-}
+}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/76315
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I64402e77996486b099acda114f2e250258b0048e
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits