From ee37eef156b5f22f0a999b1d4c3c18645b93939c Mon Sep 17 00:00:00 2001 From: John Romkey <58883+romkey@users.noreply.github.com> Date: Mon, 28 Oct 2024 11:14:23 -0700 Subject: [PATCH] Change ipaddress_ipv4address_print() to quote the IPv4Address if kind is PRINT_JSON --- shared-bindings/ipaddress/IPv4Address.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/shared-bindings/ipaddress/IPv4Address.c b/shared-bindings/ipaddress/IPv4Address.c index bf18eda0f790a..4680e60deec77 100644 --- a/shared-bindings/ipaddress/IPv4Address.c +++ b/shared-bindings/ipaddress/IPv4Address.c @@ -146,7 +146,11 @@ static void ipaddress_ipv4address_print(const mp_print_t *print, mp_obj_t self_i mp_get_buffer_raise(address_bytes, &buf_info, MP_BUFFER_READ); const uint8_t *buf = (uint8_t *)buf_info.buf; - mp_printf(print, "%d.%d.%d.%d", buf[0], buf[1], buf[2], buf[3]); + if (kind == PRINT_JSON) { + mp_printf(print, "\"%d.%d.%d.%d\"", buf[0], buf[1], buf[2], buf[3]); + } else { + mp_printf(print, "%d.%d.%d.%d", buf[0], buf[1], buf[2], buf[3]); + } } static const mp_rom_map_elem_t ipaddress_ipv4address_locals_dict_table[] = {