Skip to content

Commit

Permalink
fix: 🎨 Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienyhuel committed Dec 23, 2024
1 parent 9f53a8e commit 2d7b2fe
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Apache Common Log Format. The body of the block accepts the custom `placeholder`
log {
format transform [<template>] {
placeholder <string>
unescape_strings <bool>
unescape_strings
# other fields accepted by JSON encoder
}
}
Expand Down
12 changes: 1 addition & 11 deletions caddyfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package transformencoder
import (
"strings"

"strconv"

"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
)

Expand Down Expand Up @@ -49,19 +47,11 @@ func (se *TransformEncoder) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
d.Delete()
d.Delete()
case "unescape_strings":
// require an argument
if !d.NextArg() {
return d.ArgErr()
}
b, err := strconv.ParseBool(d.Val())
if nil == err {
se.UnescapeStrings = b
}
if d.NextArg() {
return d.ArgErr()
}
d.Delete()
d.Delete()
se.UnescapeStrings = true
default:
d.RemainingArgs() //consume line without getting values
}
Expand Down
6 changes: 3 additions & 3 deletions caddyfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func TestUnmarshalCaddyfile(t *testing.T) {
},
args: args{
d: caddyfile.NewTestDispenser(`transform {
unescape_strings true
unescape_strings
}`),
},
wantErr: false,
Expand All @@ -317,7 +317,7 @@ func TestUnmarshalCaddyfile(t *testing.T) {
},
args: args{
d: caddyfile.NewTestDispenser(`transform "{obj1>obj2>[0]}" {
unescape_strings true
unescape_strings
}`),
},
wantErr: false,
Expand All @@ -337,7 +337,7 @@ func TestUnmarshalCaddyfile(t *testing.T) {
d: caddyfile.NewTestDispenser(`transform "{obj1>obj2>[0]}" {
time_local
placeholder -
unescape_strings true
unescape_strings
time_format iso8601
}`),
},
Expand Down
5 changes: 2 additions & 3 deletions formatencoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,9 @@ func getValue(buf *buffer.Buffer, key string, unescapeStrings bool) (interface{}
case jsonparser.String:
if !unescapeStrings {
return value, true
} else {
str, _ := jsonparser.ParseString(value)
return str, true
}
str, _ := jsonparser.ParseString(value)
return str, true
case jsonparser.Array, jsonparser.Boolean, jsonparser.Null, jsonparser.Number, jsonparser.Object, jsonparser.Unknown:
// if a value exists, return it as is. A byte is a byte is a byte. The replacer handles them just fine.
return value, true
Expand Down
4 changes: 2 additions & 2 deletions formatencoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestEncodeEntry(t *testing.T) {
expectedLogString string
}{
{
name: "transform: no args",
name: "encode entry: no unescape field",
se: TransformEncoder{
Encoder: new(logging.JSONEncoder),
Template: "{msg} {username}",
Expand All @@ -47,7 +47,7 @@ func TestEncodeEntry(t *testing.T) {
expectedLogString: "lob\\nlaw john\\ndoe\n",
},
{
name: "transform: no args",
name: "encode entry: unescape field",
se: TransformEncoder{
Encoder: new(logging.JSONEncoder),
Template: "{msg} {username}",
Expand Down

0 comments on commit 2d7b2fe

Please sign in to comment.