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

Refactor: (query-params) replace hasOwnProperty with typeof check to avoid false positives #366

Conversation

Mauro-Domingues
Copy link

📝 Description

  • The way that Object.hasOwnProperty handles data is similar to Object.keys ignoring the value of the data. Objects passed as the following example result in an error:
{
  begin_date: undefined,
  end_date: undefined,
  offset: 1,
  limit: 20,
  external_reference: undefined
}
Cannot read properties of undefined (reading 'toString')
  • The change consists of treating data by its values and not by the existence of the key in the object. Null, empty string, and false will not cause errors when calling toString() because this function is defined for these values in JavaScript. Only undefined will cause an error when trying to call toString(). Checking only undefined is enough to avoid these errors.

✅ Checklist:

  • I followed the instructions indicated in Contribution Guidelines
  • I added the changes to CHANGELOG
  • Added the necessary tests for the code or functionality that I'm working on
  • I ran the tests and made sure they work
  • My branch coverage is at least 80%
  • I verified the style of my code matches the one in the project

🧰 How to reproduce

  • Not Apply.
  • Step by step of how to test, specially for bugs.
  • Links of external docs.

📸 Screenshots

  • Not Apply.
  • Before and after, if it's a fix for a bug.

📄 References

  • Not Apply.
  • Links do external documentation.
  • Diagrams.
  • Useful links.

@kelvincarvalhosilva
Copy link

Hi @Mauro-Domingues

We will analyze the proposed solution and soon integrate it into our product.
Thank you very much for your contribution!

@kelvincarvalhosilva kelvincarvalhosilva changed the title Refactor(query-params): replace hasOwnProperty with typeof check to avoid false positives Refactor: (query-params) replace hasOwnProperty with typeof check to avoid false positives Mar 19, 2025
@kelvincarvalhosilva kelvincarvalhosilva merged commit fdec521 into mercadopago:develop Mar 19, 2025
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

Successfully merging this pull request may close these issues.

2 participants