Open berdanA opened 6 days ago
Sounds like a reasonable addition to me 👍
Feel free to contribute @berdanA if you'd like.
I will publish a pull request hopefully shortly, I want to test this thoroughly
Alright, I opened a pull request with all changes and tests. I hope I did everything correctly.
What is the underlying problem you're trying to solve?
In the units.parser (or specifically in the extractNumAndUnit function in topdown/parse_bytes.go), scientific notation is not currently supported for parsing numeric values with units. This limitation impacts functionality when using OPA Gatekeeper as the policy engine in Kubernetes clusters, where certain resource specifications permit the use of scientific notation. To maintain flexibility and improve user experience, I would like to propose a solution that adds support for scientific notation without altering existing functionality.
Describe the ideal solution
Enhance the extractNumAndUnit function to detect and handle scientific notation by checking for the presence of "e" or "E" followed by a numeric sequence. This allows values in scientific notation (e.g., "1e6") to be parsed as valid numbers. The proposed code modification below demonstrates this approach.
This change would not change or inhibit existing functionality as far as I see.