From 0907b67e24f4339f2761083a599dd5e1969b28ee Mon Sep 17 00:00:00 2001 From: Tim Jones Date: Fri, 13 Dec 2019 10:26:07 -0500 Subject: [PATCH] Remove final trailing comma. Test. --- main.go | 2 +- main_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index c6b4172..6b086d0 100644 --- a/main.go +++ b/main.go @@ -95,7 +95,7 @@ func quickCheckJSON(data []byte) error { } func cleanTrailingCommas(data []byte) ([]byte, error) { - re, err := regexp.Compile(`(?ms),(\s*[}\]])`) + re, err := regexp.Compile(`,(\s*([}\]]|$))`) if err != nil { return nil, err } diff --git a/main_test.go b/main_test.go index b516b62..507c4bd 100644 --- a/main_test.go +++ b/main_test.go @@ -34,6 +34,11 @@ func TestCleanTrailingCommas(t *testing.T) { "foo": 1 }`, }, + { + name: "final trailing comma", + input: `{"foo": "bar"},`, + output: `{"foo": "bar"}`, + }, } for _, c := range cases {