fix(parser/cppcheck): monkey patch stderr
All checks were successful
submodules sync / sync (push) Successful in 44s
build / build (push) Successful in 2m10s
build / trigger-build-image (push) Successful in 13s

This commit is contained in:
张泊明518370910136 2025-10-07 21:18:35 -07:00
parent 2a35a27f7d
commit 1c70191ea8
GPG Key ID: D47306D7062CDA9D

View File

@ -17,9 +17,30 @@ type Record struct {
ID string `json:"id"` ID string `json:"id"`
} }
func (*CppCheck) parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult { // monkey patch for not escaped " in cppcheck message
func (*CppCheck) fixStderr(stderr string) string {
const prefixMarker = `"message":"`
const suffixMarker = `","id":"`
prefixIndex := strings.Index(stderr, prefixMarker)
if prefixIndex == -1 {
return stderr
}
contentStartIndex := prefixIndex + len(prefixMarker)
suffixIndex := strings.LastIndex(stderr, suffixMarker)
if suffixIndex == -1 || suffixIndex < contentStartIndex {
return stderr
}
contentEndIndex := suffixIndex
prefix := stderr[:contentStartIndex]
messageContent := stderr[contentStartIndex:contentEndIndex]
suffix := stderr[contentEndIndex:]
cleanedMessageContent := strings.ReplaceAll(messageContent, `"`, `\"`)
return prefix + cleanedMessageContent + suffix
}
func (p *CppCheck) parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
// stdout := executorResult.Files[conf.Stdout] // stdout := executorResult.Files[conf.Stdout]
stderr := executorResult.Files[conf.Stderr] stderr := p.fixStderr(executorResult.Files[conf.Stderr])
records := make([]Record, 0) records := make([]Record, 0)
lines := strings.SplitSeq(stderr, "\n") lines := strings.SplitSeq(stderr, "\n")
for line := range lines { for line := range lines {