Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libs/flags/json_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package flags

import (
"encoding/json"
"errors"
"fmt"
"os"
"reflect"
Expand All @@ -23,6 +24,9 @@ func (j *JsonFlag) String() string {

// TODO: Command.MarkFlagFilename()
func (j *JsonFlag) Set(v string) error {
if v == "" {
return errors.New("expected inline JSON or @path/to/file, got an empty string")
}
// Load request from file if it starts with '@' (like curl).
if v[0] != '@' {
j.raw = []byte(v)
Expand Down
7 changes: 7 additions & 0 deletions libs/flags/json_flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ func TestJsonFlagEmpty(t *testing.T) {
assert.Nil(t, request)
}

func TestJsonFlagEmptyValue(t *testing.T) {
var body JsonFlag

err := body.Set("")
assert.EqualError(t, err, "expected inline JSON or @path/to/file, got an empty string")
}

func TestJsonFlagInline(t *testing.T) {
var body JsonFlag

Expand Down
Loading