From 0066e6049e486fa4bbc52c062a22efb594f1cf05 Mon Sep 17 00:00:00 2001 From: Anthony <97815296+2x2anthony@users.noreply.github.com> Date: Tue, 7 Nov 2023 03:42:27 -0800 Subject: [PATCH] Fix not rendering uint64_t values greater than the int64_t max value (#278) * Fix not properly rendering uint64_t values greater than the int64_t max value * Move render check to variables subcase --- include/inja/renderer.hpp | 2 ++ single_include/inja/inja.hpp | 2 ++ test/test-renderer.cpp | 2 ++ 3 files changed, 6 insertions(+) diff --git a/include/inja/renderer.hpp b/include/inja/renderer.hpp index 354f8df7..ba784c08 100644 --- a/include/inja/renderer.hpp +++ b/include/inja/renderer.hpp @@ -56,6 +56,8 @@ class Renderer : public NodeVisitor { void print_data(const std::shared_ptr value) { if (value->is_string()) { *output_stream << value->get_ref(); + } else if (value->is_number_unsigned()) { + *output_stream << value->get(); } else if (value->is_number_integer()) { *output_stream << value->get(); } else if (value->is_null()) { diff --git a/single_include/inja/inja.hpp b/single_include/inja/inja.hpp index b2011f48..3535da0b 100644 --- a/single_include/inja/inja.hpp +++ b/single_include/inja/inja.hpp @@ -2125,6 +2125,8 @@ class Renderer : public NodeVisitor { void print_data(const std::shared_ptr value) { if (value->is_string()) { *output_stream << value->get_ref(); + } else if (value->is_number_unsigned()) { + *output_stream << value->get(); } else if (value->is_number_integer()) { *output_stream << value->get(); } else if (value->is_null()) { diff --git a/test/test-renderer.cpp b/test/test-renderer.cpp index 9963246a..68268e7f 100644 --- a/test/test-renderer.cpp +++ b/test/test-renderer.cpp @@ -18,6 +18,7 @@ TEST_CASE("types") { data["relatives"]["brother"] = "Chris"; data["relatives"]["sister"] = "Jenny"; data["vars"] = {2, 3, 4, 0, -1, -2, -3}; + data["max_value"] = 18446744073709551615ull; SUBCASE("basic") { CHECK(env.render("", data) == ""); @@ -38,6 +39,7 @@ TEST_CASE("types") { CHECK(env.render("{{ \"{{ no_value }}\" }}", data) == "{{ no_value }}"); CHECK(env.render("{{ @name }}", data) == "@name"); CHECK(env.render("{{ $name }}", data) == "$name"); + CHECK(env.render("{{max_value}}", data) == "18446744073709551615"); CHECK_THROWS_WITH(env.render("{{unknown}}", data), "[inja.exception.render_error] (at 1:3) variable 'unknown' not found"); }