Skip to content
Myr

Fix handling of empty ANSI color sequence

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix #3320

authored by Junegunn Choi · committed by Junegunn Choi · parent 65b2c06 · Browse files · 2 files+12 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+12 added−0 removed

  • other:+12 added−0 removed

2 files+12 added−0 removed

modified:src/ansi_test.go+3 added
346 unmodified lines
347 }348 }349 assert("\x1b[m", nil, "")350 assert("\x1b[m", &ansiState{attr: tui.Blink, lbg: -1}, "")351 assert("\x1b[0m", &ansiState{fg: 4, bg: 4, lbg: -1}, "")352 assert("\x1b[;m", &ansiState{fg: 4, bg: 4, lbg: -1}, "")353 assert("\x1b[;;m", &ansiState{fg: 4, bg: 4, lbg: -1}, "")354355 assert("\x1b[31m", nil, "\x1b[31;49m")356 assert("\x1b[41m", nil, "\x1b[39;41m")357
74 unmodified lines
modified:src/ansi.go+9 added
349 unmodified lines
350 state256 := 0351 ptr := &state.fg352353 var delimiter byte = 0354 count := 0355 for len(ansiCode) != 0 {356 var num int357 if num, delimiter, ansiCode = parseAnsiCode(ansiCode, delimiter); num != -1 {358 count++359 switch state256 {360 case 0:361 switch num {362 case 38:
73 unmodified lines
436 }437 }438 }439440 // Empty sequence: reset441 if count == 0 {442 state.fg = -1443 state.bg = -1444 state.attr = 0445 }446447 if state256 > 0 {448 *ptr = -1449 }450 return state
1 unmodified line