An interesting feature/bug about Go testing suite?

使用go test -cover的时候发现了一个很有意思的事情,如果被测试函数有 coverage: xxxxxx 这样的对stdout的输出,那么对应的测试里,最后输出的 ok xxxxxx yyyyys coverage: X% of statements 中,coverage会被覆盖 谷歌没搜到答案,直接抠Go源码 这个out是buf的Bytes,通过写入,关键是coveragePercentage这,居然是个非常粗暴的正则匹配 导致了这种被hack的结果

March 9, 2024 · 1 min · ChaosNyaruko