Skip to content
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

TypeError: arr[i].toUpperCase is not a function #540

Closed
renata-aldi opened this issue Oct 22, 2021 · 10 comments
Closed

TypeError: arr[i].toUpperCase is not a function #540

renata-aldi opened this issue Oct 22, 2021 · 10 comments

Comments

@renata-aldi
Copy link

renata-aldi commented Oct 22, 2021

we got this error when run test with mocha
Node JS Version : 8.17.0
NPM version : 6.13.4
UA Parser JS Version : 0.7.23

`�[91m<my_project_folder>node_modules/ua-parser-js/dist/ua-parser.min.js:4
(function(window,undefined){"use strict";var LIBVERSION="0.7.28",EMPTY="",UNKNOWN="?",FUNC_TYPE="function",UNDEF_TYPE="undefined",OBJ_TYPE="object",STR_TYPE="string",MAJOR="major",MODEL="model",NAME="name",TYPE="type",VENDOR="vendor",VERSION="version",ARCHITECTURE="architecture",CONSOLE="console",MOBILE="mobile",TABLET="tablet",SMARTTV="smarttv",WEARABLE="wearable",EMBEDDED="embedded",UA_MAX_LENGTH=255;var AMAZON="Amazon",APPLE="Apple",ASUS="ASUS",BLACKBERRY="BlackBerry",BROWSER="Browser",CHROME="Chrome",EDGE="Edge",FIREFOX="Firefox",GOOGLE="Google",HUAWEI="Huawei",LG="LG",MICROSOFT="Microsoft",MOTOROLA="Motorola",OPERA="Opera",SAMSUNG="Samsung",SONY="Sony",XIAOMI="Xiaomi",ZEBRA="Zebra";var extend=function(regexes,extensions){var mergedRegexes={};for(var i in regexes){if(extensions[i]&&extensions[i].length%2===0){mergedRegexes[i]=extensions[i].concat(regexes[i])}else{mergedRegexes[i]=regexes[i]}}return mergedReg

TypeError: arr[i].toUpperCase is not a function
@renata-aldi renata-aldi changed the title error ua-parser-js on version 0.7.23 TypeError: arr[i].toUpperCase is not a function Oct 22, 2021
@alex-drocks
Copy link

Don't trust ui-parser-js module until issue #536 is solved

@charlesmass2
Copy link

charlesmass2 commented Oct 23, 2021

@renata-aldi This seems to happen when extending Array.prototype.
See enumerize function in ua-parser :

        enumerize = function (arr) {
            var enums = {};
            for (var i in arr) {
                enums[arr[i].toUpperCase()] = arr[i];
            }
            return enums;
        },

for...in loops should always check properties with hasOwnProperty. Which would prevent the issue you're facing.

In the meantime, if you don't need to support old browsers, you can replace your Array.prototype extensions with something like :

Object.defineProperty(Array.prototype, 'newFunction', {
    enumerable: false,
    value: function(fun) {
        // code to find element in array
    }
});

@mainam
Copy link

mainam commented Oct 25, 2021

My solution to resolve this problem, create a prototype toUpperCase function to prevent error.

Object.prototype.toUpperCase =
Object.prototype.toUpperCase ||
function () {
return null;
};

@renata-aldi
Copy link
Author

i already fixed this when upgrading to 0.7.30 version
thank you guys :)

@MikiDi
Copy link

MikiDi commented Oct 26, 2021

I don't think this was fixed in 0.7.30. #547 should fix this, but no release including this patch is available yet.

@mikemellor11
Copy link

After regenerating a package-lock file just now we're just hit this issue also. Hopefully a fix can get pushed out soon.

@hopefuture
Copy link

NPM dependencies are not updated in the latest version(1.0.1)

@hopefuture
Copy link

i already fixed this when upgrading to 0.7.30 version thank you guys :)

NPM dependencies are not updated in the latest version(1.0.1)

@faisalman
Copy link
Owner

Fixed in 0.7.31 / 1.0.2

@karthickparamasivam
Copy link

Thanks @faisalman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants