summaryrefslogtreecommitdiff
path: root/vendor/github.com/tdewolff/minify/v2/common.go
diff options
context:
space:
mode:
authorLibravatar kim <grufwub@gmail.com>2025-05-22 16:27:55 +0200
committerLibravatar kim <gruf@noreply.codeberg.org>2025-05-22 16:27:55 +0200
commitb6ff55662e0281c0d6e111f9307625ef695df2fa (patch)
tree5f7761efa0b51a7a7d56f96fce3681c8e9b66fe9 /vendor/github.com/tdewolff/minify/v2/common.go
parent[chore/woodpecker] don't make `test` depend on `lint` (#4189) (diff)
downloadgotosocial-b6ff55662e0281c0d6e111f9307625ef695df2fa.tar.xz
[chore] update dependencies (#4188)
Update dependencies: - github.com/gin-gonic/gin v1.10.0 -> v1.10.1 - github.com/gin-contrib/sessions v1.10.3 -> v1.10.4 - github.com/jackc/pgx/v5 v5.7.4 -> v5.7.5 - github.com/minio/minio-go/v7 v7.0.91 -> v7.0.92 - github.com/pquerna/otp v1.4.0 -> v1.5.0 - github.com/tdewolff/minify/v2 v2.23.5 -> v2.23.8 - github.com/yuin/goldmark v1.7.11 -> v1.7.12 - go.opentelemetry.io/otel{,/*} v1.35.0 -> v1.36.0 - modernc.org/sqlite v1.37.0 -> v1.37.1 Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4188 Reviewed-by: Daenney <daenney@noreply.codeberg.org> Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/github.com/tdewolff/minify/v2/common.go')
-rw-r--r--vendor/github.com/tdewolff/minify/v2/common.go47
1 files changed, 23 insertions, 24 deletions
diff --git a/vendor/github.com/tdewolff/minify/v2/common.go b/vendor/github.com/tdewolff/minify/v2/common.go
index 3773a9b47..8efb5b9f9 100644
--- a/vendor/github.com/tdewolff/minify/v2/common.go
+++ b/vendor/github.com/tdewolff/minify/v2/common.go
@@ -328,7 +328,9 @@ func Number(num []byte, prec int) []byte {
// normExp would be the exponent if it were normalised (0.1 <= f < 1)
n := 0
normExp := 0
- if dot == start {
+ if start == end {
+ return num // no number before exponent
+ } else if dot == start {
for i = dot + 1; i < end; i++ {
if num[i] != '0' {
n = end - i
@@ -404,24 +406,24 @@ func Number(num []byte, prec int) []byte {
} else if zeroes < 0 {
copy(num[start+1:], num[start:dot])
num[start] = '.'
+ } else {
+ return num
}
num[end] = 'e'
num[end+1] = '-'
end += 2
- for i := end + lenNormExp - 1; end <= i; i-- {
+ for i := end + lenNormExp - 2; end <= i; i-- {
num[i] = -byte(normExp%10) + '0'
normExp /= 10
}
- end += lenNormExp
- } else if -lenIntExp-1 <= normExp {
+ end += lenNormExp - 1
+ } else if -lenIntExp <= normExp {
// case 3: print number without exponent
zeroes := -normExp
if 0 < zeroes {
- // dot placed at the front and negative exponent, adding zeroes
- newDot := end - n - zeroes - 1
- if newDot != dot {
- d := start - newDot
- if 0 < d {
+ // place dot at the front, adding zeroes after the dot
+ if newDot := end - n - zeroes - 1; newDot != dot {
+ if d := start - newDot; 0 < d {
if dot < end {
// copy original digits after the dot towards the end
copy(num[dot+1+d:], num[dot+1:end])
@@ -444,18 +446,18 @@ func Number(num []byte, prec int) []byte {
}
}
} else {
- // dot placed in the middle of the number
- if dot == start {
- // when there are zeroes after the dot
- dot = end - n - 1
- start = dot
- } else if end <= dot {
+ // place dot in the middle of the number
+ if end <= dot {
// when input has no dot in it
dot = end
end++
+ } else if dot == start {
+ // when there are zeroes after the dot
+ dot = end - n - 1
+ start = dot
}
- newDot := start + normExp
// move digits between dot and newDot towards the end
+ newDot := start + normExp
if dot < newDot {
copy(num[dot:], num[dot+1:newDot+1])
} else if newDot < dot {
@@ -468,11 +470,11 @@ func Number(num []byte, prec int) []byte {
// find new end, considering moving numbers to the front, removing the dot and increasing the length of the exponent
newEnd := end
if dot == start {
- newEnd = start + n
+ newEnd = dot + n
} else {
newEnd--
}
- newEnd += 2 + lenIntExp
+ newEnd += 1 + lenIntExp
exp := intExp
lenExp := lenIntExp
@@ -490,19 +492,16 @@ func Number(num []byte, prec int) []byte {
} else {
// it does not save space and will panic, so we revert to the original representation
exp = origExp
- lenExp = 1
- if origExp <= -10 || 10 <= origExp {
- lenExp = strconv.LenInt(int64(origExp))
- }
+ lenExp = strconv.LenInt(int64(origExp))
}
num[end] = 'e'
num[end+1] = '-'
end += 2
- for i := end + lenExp - 1; end <= i; i-- {
+ for i := end + lenExp - 2; end <= i; i-- {
num[i] = -byte(exp%10) + '0'
exp /= 10
}
- end += lenExp
+ end += lenExp - 1
}
if neg {