@hamburger123456 opened this Issue on July 12th 2018

If you call the function

logEvent(category, action, name, value, customData, callback)

without parameter it shout gives an error.

(logConsoleError(‘Error while logging event: Parameters category and action must not be empty or filled with whitespaces’);

But it doesn’t. Because the line

 if (trim(String(category)).length === 0 || trim(String(action)).length === 0) { ...

will not work. String(category) returns always 9 (the length of the word undefined) when categorie is empty
So the error will never been showed.

@fdellwing commented on July 12th 2018 Contributor

I do not have time to provide a PR atm, but this should be fixxed really simple.

if (category === undefined || action === undefined || trim(String(category)).length === 0 || trim(String(action)).length === 0) { ...
@tsteur commented on July 12th 2018 Member

@fdellwing just fyi to make JSLint in the tests happy we will need to use something like typeof value === "undefined". Should be definitely an easy fix

@fdellwing commented on July 12th 2018 Contributor

Maybe not the right place for that, you can DM me in the forums with an answer if you want:

I'm not experienced with JSLint, what is it's problem with ˋvalue === undefinedˋ? This is perfectly valid JS, isn't it?

@tsteur commented on July 12th 2018 Member

It definitely is valid. It's just when the JS tests run, there is a test to check if JSLint is "happy" and it usually complains about it.

@hamburger123456 commented on July 13th 2018

whats about
if (!category || ...
and:
if you use trim, why not here also?
buildEventRequest(trim(String(category)), trim(String(action)), name, value),

@fdellwing commented on July 13th 2018 Contributor

Never use something like !category if you have no control over the input, you are asking for trouble.

To make it more clear what I mean, check the output of the following lines (both being empty strings):

("") ? "truthey" : "falsey";
(new String("")) ? "truthey" : "falsey";
This Issue was closed on May 25th 2020
Powered by GitHub Issue Mirror