DEV Community

Cover image for Hacktoberfest: PR #4
Omar Hussein
Omar Hussein

Posted on

Hacktoberfest: PR #4

My recent journey led me to validator.js, a popular JavaScript library used for data validation. In this library, an issue was raised about a bug in the isInt function, which game an idea to fix this as well as another function since I thought they might share the same type of logic; the isFloat function.

The Challenge: Bug Hunting in isInt and isFloat

The bug appeared when the options passed to the isInt and isFloat functions were null or undefined. These functions, crucial for checking integer and floating-point values, were not handling these scenarios as gracefully as they should have been. The codebase was very well organized in the source code section and was easy to navigate without much advanced search. However, the test directory - although very easy to navigate with a simple text search - could have been better organized, it would be interesting to see if i could contribute to refactoring the tests section of the codebase to make it easier to understand!

Solution Part 1: Modifying isInt and isFloat Functions

I modified the isInt and isFloat functions to handle null and undefined options gracefully. By implementing conditional checks, I made sure that the functions continued to validate integers and floats effectively, regardless of the provided options.

Solution Part 2: Strengthening the Validation Suite

To validate my modifications and to make sure no other functions break due to the changes since these are core functions which other functions heavily depend on, I expanded the existing test suite. I created new test cases specifically designed to assess the functions’ behavior when null and undefined options are passed through the parameters. These tests served as a safety net, confirming that the modified isInt and isFloat functions performed flawlessly under a variety of scenarios. These modification can be found in this pull request

Open-Source is FUN!!

Contributing to Validator.js was a fun experience that reinforced the spirit of open-source collaboration. By fixing a bug and enhancing the library’s core functions, I hope play a part in empowering developers worldwide with a more robust validation tool.

In the spirit of open source, I encourage fellow developers to join the movement. Whether you’re fixing bugs, adding features, or improving documentation, your contribution matters. Together, we can create a more reliable and efficient digital world, one pull request at a time. Happy hacking!

Top comments (0)