This issue has been created
There are 9 updates.
 
 
XWiki Platform / cid:jira-generated-image-avatar-3d067b86-ba35-4e81-ba15-64b6ae7b3ef2 XWIKI-22377 Closed

Prototype.js can still break the standard Array.from method

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-ab0de107-b812-4e52-8b00-fc601170a973 Marius Dumitru Florea created this issue on 31/Jul/24 15:22
 
Summary: Prototype.js can still break the standard Array.from method
Issue Type: cid:jira-generated-image-avatar-3d067b86-ba35-4e81-ba15-64b6ae7b3ef2 Bug
Affects Versions: 13.10.10, 14.4.6, 14.9-rc-1
Assignee: Unassigned
Components: Web - Templates & Resources
Created: 31/Jul/24 15:22
Priority: cid:jira-generated-image-static-major-0c037ee8-a512-4c42-9fe7-4a1768372787 Major
Reporter: Marius Dumitru Florea
Description:

The fix we did in XWIKI-20183 is not perfect. We restore the original Array.from using a setTimeout(() => {}, 0) hoping that our callback is called after the Prototpye.js code is loaded (and Array.from is overridden). This happens most of the time in practice because Prototype.js is cached. But it is possible that our callback is called to early, when Prototype.js is not cached and / or the network is slow. I can reproduce this consistently using Chrome with cache disabled and setting throttling to "Slow 4G" or even "Fast 4G".

This issue causes for instance the MathJax macro to fail. I used this content to reproduce:

Normal Wiki text followed by a formula

{{mathjax}}
\begin{eqnarray}
1 & = & a x + b y\label{eq:first} \\
0 & = & c x + d y\label{eq:second}
\end{eqnarray}
{{/mathjax}}

Solving equation {{mathjax}}\ref{eq:second}{{/mathjax}} for {{mathjax}}x{{/mathjax}} and substituting back into equation {{mathjax}}\ref{eq:first}{{/mathjax}} yields

{{mathjax}}
\begin{equation}
y = \frac{c}{cb-ad}
\end{equation}
{{/mathjax}}

The failure is in tex-chtml.js at this line:

Array.from(this._fallback)[0].item(c, u)

where this._fallback is an iterable object, as per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol . Prototype's implementation of Array.from is too old to support iterable objects.

As a result the MathJax macro shows "Math input error", and the JavaScript exception is:

Cannot read properties of undefined (reading 'item')

because Prototype's Array.from returns an empty array when given an iterable object.

 
 

9 updates

 
cid:jira-generated-image-avatar-ab0de107-b812-4e52-8b00-fc601170a973 Changes by Marius Dumitru Florea on 31/Jul/24 15:24
 
Fix Version: 16.4.2
Fix Version: 16.7.0-rc-1
Fix Version: 15.10.12
Difficulty: Unknown Medium
Documentation: N/A
Documentation in Release Notes: N/A
Assignee: Marius Dumitru Florea
Resolution: Fixed
Status: Open Closed