From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 50E431F934 for ; Sat, 2 Oct 2021 08:16:22 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/2] lei inspect: integerize "bytes" and "lines" fields Date: Sat, 2 Oct 2021 08:16:21 +0000 Message-Id: <20211002081622.3252-2-e@80x24.org> In-Reply-To: <20211002081622.3252-1-e@80x24.org> References: <20211002081622.3252-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: These are always numeric, but none of the Perl code cares; but we want to prevent JSON from quoting them. --- lib/PublicInbox/LeiInspect.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/LeiInspect.pm b/lib/PublicInbox/LeiInspect.pm index 2158b996a3a4..f18e31c5c8f4 100644 --- a/lib/PublicInbox/LeiInspect.pm +++ b/lib/PublicInbox/LeiInspect.pm @@ -13,6 +13,12 @@ use PublicInbox::Config; use PublicInbox::MID qw(mids); use PublicInbox::NetReader qw(imap_uri nntp_uri); +sub _json_prep ($) { + my ($smsg) = @_; + $smsg->{$_} += 0 for qw(bytes lines); # integerize + +{ %$smsg } # unbless and scalarize +} + sub inspect_blob ($$) { my ($lei, $oidhex) = @_; my $ent = {}; @@ -143,7 +149,7 @@ sub inspect_num ($$) { } if ($ibx && $ibx->over) { my $smsg = $ibx->over->get_art($num); - $ent->{smsg} = { %$smsg } if $smsg; + $ent->{smsg} = _json_prep($smsg) if $smsg; } defined($docid) ? inspect_docid($lei, $docid, $ent) : $ent; } @@ -164,7 +170,7 @@ sub inspect_mid ($$) { if ($ibx && $ibx->over) { my ($id, $prev); while (my $smsg = $ibx->over->next_by_mid($mid, \$id, \$prev)) { - push @{$ent->{smsg}}, { %$smsg } + push @{$ent->{smsg}}, _json_prep($smsg); } } $ent;