[Bug 1726] invalid json generated by ipset list -output json

bugzilla-daemon at netfilter.org bugzilla-daemon at netfilter.org
Tue Dec 5 11:36:11 CET 2023


https://bugzilla.netfilter.org/show_bug.cgi?id=1726

--- Comment #1 from mark at glines.org ---
Created attachment 732
  --> https://bugzilla.netfilter.org/attachment.cgi?id=732&action=edit
Fix ipset list -output json -name

This fixes -output json -name.

Adds curly braces.  Adds a static flag to keep track of whether a comma is
necessary.  This is very similar to how list_create() handles it, in the
non-"-name" case.

Output before:

---
% sudo src/ipset list -output json -name
[
"name" : "blocklist.de.ipv4"
"name" : "blocklist.de.ipv6"

]
---

Output after:

---
 sudo src/ipset list -output json -name
[
  { "name" : "blocklist.de.ipv4" },
  { "name" : "blocklist.de.ipv6" }
]
---

While testing this, I added an "else" to solve a logic problem.  It wants to do
one thing for xml, another thing for json, and a third thing for plain text. 
But because of the missing "else", xml output contains both xml and plaintext. 
Like this:

---
% sudo src/ipset list -output xml -name
<ipsets>
<ipset name="blocklist.de.ipv4"/>
blocklist.de.ipv4
<ipset name="blocklist.de.ipv6"/>
blocklist.de.ipv6
</ipsets>
---

The added "else" resolves that.

---
% sudo src/ipset list -output xml -name
<ipsets>
<ipset name="blocklist.de.ipv4"/>
<ipset name="blocklist.de.ipv6"/>
</ipsets>
---

-- 
You are receiving this mail because:
You are watching all bug changes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.netfilter.org/pipermail/netfilter-buglog/attachments/20231205/bb2d32d6/attachment.html>


More information about the netfilter-buglog mailing list