mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
metrics: Fix divide by zero error
Under certain conditions, `howSimilarString` could reach a divide-by- zero situation which causes bogus values to print in the cache potential column of the template hints output. This situation essentially causes a `int(math.NaN())` value to be returned and hilarity ensues thereafter.
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
805b21555e
commit
6a5acd753a
@@ -281,6 +281,10 @@ func howSimilarStrings(a, b string) int {
|
||||
}
|
||||
}
|
||||
|
||||
if common == 0 && common == len(af) {
|
||||
return 100
|
||||
}
|
||||
|
||||
return int(math.Floor((float64(common) / float64(len(af)) * 100)))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user