Skip to content

Commit a71af9c

Browse files
Manuel Alonsothinkerou
Manuel Alonso
andauthored
removing log injection (#2277)
Co-authored-by: thinkerou <[email protected]>
1 parent 1d055af commit a71af9c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

logger.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ var defaultLogFormatter = func(param LogFormatterParams) string {
141141
// Truncate in a golang < 1.8 safe way
142142
param.Latency = param.Latency - param.Latency%time.Second
143143
}
144-
return fmt.Sprintf("[GIN] %v |%s %3d %s| %13v | %15s |%s %-7s %s %s\n%s",
144+
return fmt.Sprintf("[GIN] %v |%s %3d %s| %13v | %15s |%s %-7s %s %#v\n%s",
145145
param.TimeStamp.Format("2006/01/02 - 15:04:05"),
146146
statusColor, param.StatusCode, resetColor,
147147
param.Latency,

logger_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func TestLoggerWithFormatter(t *testing.T) {
158158

159159
router := New()
160160
router.Use(LoggerWithFormatter(func(param LogFormatterParams) string {
161-
return fmt.Sprintf("[FORMATTER TEST] %v | %3d | %13v | %15s | %-7s %s\n%s",
161+
return fmt.Sprintf("[FORMATTER TEST] %v | %3d | %13v | %15s | %-7s %#v\n%s",
162162
param.TimeStamp.Format("2006/01/02 - 15:04:05"),
163163
param.StatusCode,
164164
param.Latency,
@@ -275,11 +275,11 @@ func TestDefaultLogFormatter(t *testing.T) {
275275
isTerm: false,
276276
}
277277

278-
assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 | 200 | 5s | 20.20.20.20 | GET /\n", defaultLogFormatter(termFalseParam))
279-
assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 | 200 | 2743h29m3s | 20.20.20.20 | GET /\n", defaultLogFormatter(termFalseLongDurationParam))
278+
assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 | 200 | 5s | 20.20.20.20 | GET \"/\"\n", defaultLogFormatter(termFalseParam))
279+
assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 | 200 | 2743h29m3s | 20.20.20.20 | GET \"/\"\n", defaultLogFormatter(termFalseLongDurationParam))
280280

281-
assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 |\x1b[97;42m 200 \x1b[0m| 5s | 20.20.20.20 |\x1b[97;44m GET \x1b[0m /\n", defaultLogFormatter(termTrueParam))
282-
assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 |\x1b[97;42m 200 \x1b[0m| 2743h29m3s | 20.20.20.20 |\x1b[97;44m GET \x1b[0m /\n", defaultLogFormatter(termTrueLongDurationParam))
281+
assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 |\x1b[97;42m 200 \x1b[0m| 5s | 20.20.20.20 |\x1b[97;44m GET \x1b[0m \"/\"\n", defaultLogFormatter(termTrueParam))
282+
assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 |\x1b[97;42m 200 \x1b[0m| 2743h29m3s | 20.20.20.20 |\x1b[97;44m GET \x1b[0m \"/\"\n", defaultLogFormatter(termTrueLongDurationParam))
283283

284284
}
285285

0 commit comments

Comments
 (0)