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

fix: divide by zero now does not crash #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xandrefreire
Copy link

@xandrefreire xandrefreire commented May 29, 2024

Hello,

Thank you for this library.

Bug Fix: Division by Zero

I have identified a runtime crash issue caused by division by zero. For instance, the following code snippet causes the library to crash:

let rule =
"""
{ "/" : [10, 0] }
"""

// Example parsing
let result: String? = try? JSONLogicClient.applyRule(rule, to: nil)

print("result = \(String(describing: result))")

This pull request implements a fix to prevent this crash.

Additional Observations

  1. Handling Nullable Operands in Arithmetic Operations:

There are similar crashes when operands are null. For example:

let rule =
"""
{ "/" : [10, null] }
"""

// Example parsing
let result: String? = try? JSONLogicClient.applyRule(rule, to: nil)

print("result = \(String(describing: result))")

This likely happens because null is treated as zero.

  1. Logical Operations with or and null:

This is a valid expression and returns true:

let rule =
"""
{ "or" : [true, null] }
"""

// Example parsing
let result: String? = try? JSONLogicClient.applyRule(rule, to: nil)

print("result = \(String(describing: result))")
  1. Logical Operations with and and null:

However, this expression returns nil:

let rule =
"""
{ "and" : [true, null] }
"""

// Example parsing
let result: String? = try? JSONLogicClient.applyRule(rule, to: nil)

print("result = \(String(describing: result))")

It would be beneficial to handle nullable operands more predictably.

Thank you for your time reviewing this pull request.

Best regards,

Alexandre

@xandrefreire xandrefreire mentioned this pull request May 29, 2024
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.

1 participant