Skip to content

Commit ee37eef

Browse files
committed
Change ipaddress_ipv4address_print() to quote the IPv4Address if kind is PRINT_JSON
1 parent 98cc153 commit ee37eef

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

shared-bindings/ipaddress/IPv4Address.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ static void ipaddress_ipv4address_print(const mp_print_t *print, mp_obj_t self_i
146146
mp_get_buffer_raise(address_bytes, &buf_info, MP_BUFFER_READ);
147147

148148
const uint8_t *buf = (uint8_t *)buf_info.buf;
149-
mp_printf(print, "%d.%d.%d.%d", buf[0], buf[1], buf[2], buf[3]);
149+
if (kind == PRINT_JSON) {
150+
mp_printf(print, "\"%d.%d.%d.%d\"", buf[0], buf[1], buf[2], buf[3]);
151+
} else {
152+
mp_printf(print, "%d.%d.%d.%d", buf[0], buf[1], buf[2], buf[3]);
153+
}
150154
}
151155

152156
static const mp_rom_map_elem_t ipaddress_ipv4address_locals_dict_table[] = {

0 commit comments

Comments
 (0)