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

Issue in piwik.js function logEvent #13165

Closed
hamburger123456 opened this issue Jul 12, 2018 · 6 comments · Fixed by #15980
Closed

Issue in piwik.js function logEvent #13165

hamburger123456 opened this issue Jul 12, 2018 · 6 comments · Fixed by #15980
Labels
Bug For errors / faults / flaws / inconsistencies etc. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.

Comments

@hamburger123456
Copy link

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
Copy link
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
Copy link
Member

tsteur commented Jul 12, 2018

@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

@tsteur tsteur added Bug For errors / faults / flaws / inconsistencies etc. Help wanted Beginner friendly issues or issues where we'd highly appreciate community's help and involvement. labels Jul 12, 2018
@fdellwing
Copy link
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
Copy link
Member

tsteur commented Jul 12, 2018

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
Copy link
Author

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

@fdellwing
Copy link
Contributor

fdellwing commented Jul 13, 2018

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";

@Findus23 Findus23 removed the Help wanted Beginner friendly issues or issues where we'd highly appreciate community's help and involvement. label May 24, 2020
@mattab mattab added the not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. label Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants