Skip to content

Checkout page could hang for Javascript error #10975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2017
Merged

Checkout page could hang for Javascript error #10975

merged 1 commit into from
Oct 18, 2017

Conversation

angelo983
Copy link
Member

Description

Wrong evaluating check comparison with 'undefined' of variable 'position' let hang Checkout Page
https://stackoverflow.com/a/5076962 (difference between null and undefined in JavaScript)

Fixed Issues (if relevant)

in lib/web/mage/utils/arrays.js
Line 104 to 128

if (typeof position === 'undefined') { // line 104 - fixed issue transcribed below
    position = -1;
} else if (typeof position === 'string') {
    position = isNaN(+position) ? position : +position;
}

newIndex = position;

if (~currentIndex) {
    target = container.splice(currentIndex, 1)[0];

    if (typeof item === 'string') {
        item = target;
    }
}

if (typeof position !== 'number') {
    target = position.after || position.before || position; // line 121

    newIndex = getIndex(target, container);

    if (~newIndex && (position.after || newIndex >= currentIndex)) {
        newIndex++;
    }
}

Error in line 121 because position value is NULL and this value is not managed in the script

This is the only change to apply:
lib/web/mage/utils/arrays.js
Line 104
from
if (typeof position === 'undefined') {
to
if (typeof position === 'undefined' || position == null) {

Contribution checklist

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Sep 20, 2017

CLA assistant check
All committers have signed the CLA.

@angelo983 angelo983 mentioned this pull request Sep 20, 2017
@angelo983 angelo983 changed the base branch from develop to 2.1-develop September 20, 2017 17:59
@orlangur
Copy link
Contributor

Please provide additional details in the issue itself.

@angelo983
Copy link
Member Author

@orlangur I believe instead that the programmer who wrote that line of code made the one mistake as expressed in the link https://stackoverflow.com/a/5076962 (difference between null and undefined in JavaScript).
If you are not convinced of this, state in what scenario the position should be of undefined type since that case is handled in the code
Summary:

Why YES?
if (typeof position === 'undefined') {

(My proposal)
if (typeof position === 'undefined' || position == null) {

@angelo983
Copy link
Member Author

Hello, still updates needed?

@orlangur
Copy link
Contributor

#9984 needs to be rechecked first.

@okorshenko okorshenko self-assigned this Oct 16, 2017
@okorshenko okorshenko added this to the October 2017 milestone Oct 16, 2017
@magento-team magento-team merged commit 60f47fc into magento:2.1-develop Oct 18, 2017
@angelo983 angelo983 deleted the 2.1-develop branch October 19, 2017 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants