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

"Nullness" of a JSON null is lost while iterating using formap #781

Closed
tiymat opened this issue Jan 5, 2024 · 4 comments · Fixed by #782
Closed

"Nullness" of a JSON null is lost while iterating using formap #781

tiymat opened this issue Jan 5, 2024 · 4 comments · Fixed by #782
Labels
bug Unexpected behavior deployed to `develop` Feature built. Currently BETA testing in the `develop` branch

Comments

@tiymat
Copy link
Contributor

tiymat commented Jan 5, 2024

Describe the bug:
When iterating over a JSON object using formap, is-null will always report the value as being non-null.

Expected behaviour:
is-null should behave the same whether or not it's invoked on the value of an object in a formap loop.

Screenshots:

~ » %{ "foo": null } -> set x
~ » if { is-null $x['foo'] } then { out "foo is null" } else { out "foo is NOT null" }
foo is null
~ » $x -> formap k v { if { is-null v } then { out "$k is null" } else { out "$k is NOT null" } }
foo is NOT null

Platform (please complete the following information):

  • OS, output from uname -a if supported: Ubuntu 23.04
  • Terminal Emulator: GNOME Terminal
  • Murex version, output from version --no-app-name: 5.3.6000

Additional context:
Can be worked around by disregarding the variable formap uses for the value like so

~ » $x -> formap k v { if { is-null $x[$k] } then { out "$k is null" } else { out "$k is NOT null" } }
foo is null

but I'm not sure if it's safe to access the value in this way while iterating over the object?

@tiymat tiymat added the bug Unexpected behavior label Jan 5, 2024
@lmorg
Copy link
Owner

lmorg commented Jan 5, 2024

Looks like you've uncovered not one, but two bugs in the parser.

null bareword parsed as string:

» %{ "foo": null }
{
    "foo": "null"
}

variables are tokenised for is-null parameters

» $foo = "bar"
» is-null foo
foo: defined and not null
» is-null $foo
bar: undefined or null

Both of these are trivially fixable so I'll get an update pushed to develop shortly

@lmorg lmorg added the in progress Issue is currently being worked on (possibly in a feature branch) label Jan 5, 2024
lmorg added a commit that referenced this issue Jan 5, 2024
@lmorg lmorg added the deployed to `develop` Feature built. Currently BETA testing in the `develop` branch label Jan 5, 2024
@lmorg lmorg linked a pull request Jan 5, 2024 that will close this issue
@lmorg
Copy link
Owner

lmorg commented Jan 5, 2024

@tiymat pushed a fix to develop. I'll probably put this live in the next day or two because it's a low impact change.

@tiymat
Copy link
Contributor Author

tiymat commented Jan 6, 2024

In testing the develop version (5.3.7000) I noticed a potentially-related issue.

In JSON objects constructed with %{} syntax, is-null seems to interpret empty strings as nulls, contradicting the documentation which says "Zero length strings [...] are all not null."

tmp » cat test.mx
#!/usr/bin/murex

%{ "foo": "" } -> formap key value {
	if { is-null value } then {
		out "value is null"
	} else {
		out "value is NOT null"
	}
}
tmp » ./test.mx
value is null

Edit: I guess the issue isn't with is-null itself but rather how the JSON object is being parsed/constructed.

~ » %{ "foo": '' }
{
    "foo": null
}

@lmorg
Copy link
Owner

lmorg commented Jan 6, 2024

Good spot.

The parser for object creator was a little slapdash. I'm pretty sure I wrote that code wrapped under a blanket while fighting off covid. Which also explains why the tests aren't thorough enough.

I'm going to merge the changes I have currently and will rewrite the object creator parser for a new release.

@lmorg lmorg closed this as completed in #782 Jan 6, 2024
lmorg added a commit that referenced this issue Jan 6, 2024
#781 two parser bugs affecting `is-null`
@lmorg lmorg removed the in progress Issue is currently being worked on (possibly in a feature branch) label Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected behavior deployed to `develop` Feature built. Currently BETA testing in the `develop` branch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants