From 8f6d57f58eb7035dbeb8009bbf030b3b3587226b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 4 Oct 2023 12:08:14 +0200 Subject: [PATCH] encoder_lua: Handle explicitly positive infinity --- pkg/yqlib/doc/usage/lua.md | 4 ++++ pkg/yqlib/encoder_lua.go | 2 +- pkg/yqlib/lua_test.go | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/yqlib/doc/usage/lua.md b/pkg/yqlib/doc/usage/lua.md index d6f067e4..6b6dcc8b 100644 --- a/pkg/yqlib/doc/usage/lua.md +++ b/pkg/yqlib/doc/usage/lua.md @@ -129,6 +129,8 @@ numbers: - octal: 0o30 - float: 123.45 - infinity: .inf + plus_infinity: +.inf + minus_infinity: -.inf - not: .nan ``` @@ -162,6 +164,8 @@ return { }, { ["infinity"] = (1/0); + ["plus_infinity"] = (1/0); + ["minus_infinity"] = (-1/0); }, { ["not"] = (0/0); diff --git a/pkg/yqlib/encoder_lua.go b/pkg/yqlib/encoder_lua.go index d1bb81aa..8efa1889 100644 --- a/pkg/yqlib/encoder_lua.go +++ b/pkg/yqlib/encoder_lua.go @@ -292,7 +292,7 @@ func (le *luaEncoder) encodeAny(writer io.Writer, node *yaml.Node) error { return writeString(writer, strings.ToLower(node.Value)) case "!!float": switch strings.ToLower(node.Value) { - case ".inf": + case ".inf", "+.inf": return writeString(writer, "(1/0)") case "-.inf": return writeString(writer, "(-1/0)") diff --git a/pkg/yqlib/lua_test.go b/pkg/yqlib/lua_test.go index ddcbd023..bb36e9cc 100644 --- a/pkg/yqlib/lua_test.go +++ b/pkg/yqlib/lua_test.go @@ -135,6 +135,8 @@ numbers: - octal: 0o30 - float: 123.45 - infinity: .inf + plus_infinity: +.inf + minus_infinity: -.inf - not: .nan `, expected: `return { @@ -161,6 +163,8 @@ numbers: }, { ["infinity"] = (1/0); + ["plus_infinity"] = (1/0); + ["minus_infinity"] = (-1/0); }, { ["not"] = (0/0);