Skip to content

Commit 4f43cfc

Browse files
committed
Remove unsafe
1 parent 1082e03 commit 4f43cfc

File tree

4 files changed

+6
-18
lines changed

4 files changed

+6
-18
lines changed

handlers/scraper/data.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (i *InstaData) parseTimeSliceImpl(embedBody []byte) error {
150150
if tt == js.StringToken && bytes.Contains(text, []byte("shortcode_media")) {
151151
// Strip quotes from start and end
152152
text = text[1 : len(text)-1]
153-
unescapeData := utils.UnescapeJSONString(utils.B2S(text))
153+
unescapeData := utils.UnescapeJSONString(string(text))
154154
if !gjson.Valid(unescapeData) {
155155
return errors.New("failed to parse data from TimeSliceImpl")
156156
}
@@ -387,14 +387,14 @@ func GetData(postID string) (*InstaData, error) {
387387
if dataBucket == nil {
388388
return nil
389389
}
390-
dataBucket.Put(utils.S2B(item.PostID), bb)
390+
dataBucket.Put([]byte(item.PostID), bb)
391391

392392
ttlBucket := tx.Bucket([]byte("ttl"))
393393
if ttlBucket == nil {
394394
return nil
395395
}
396396
expTime := strconv.FormatInt(time.Now().Add(24*time.Hour).UnixNano(), 10)
397-
ttlBucket.Put(utils.S2B(expTime), utils.S2B(item.PostID))
397+
ttlBucket.Put([]byte(expTime), []byte(item.PostID))
398398
return nil
399399
})
400400
if err != nil {

main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"flag"
55
"instafix/handlers"
66
scraper "instafix/handlers/scraper"
7-
"instafix/utils"
87
"instafix/views"
98
"log/slog"
109
"net/http"
@@ -120,7 +119,7 @@ func evictCache() {
120119
}
121120
c := ttlBucket.Cursor()
122121
for k, v := c.First(); k != nil; k, v = c.Next() {
123-
if n, err := strconv.ParseInt(utils.B2S(k), 10, 64); err == nil {
122+
if n, err := strconv.ParseInt(string(k), 10, 64); err == nil {
124123
if n < curTime {
125124
ttlBucket.Delete(k)
126125
dataBucket.Delete(v)

utils/jsonesc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func UnescapeJSONString(s string) string {
120120
}
121121

122122
// Slow path - unescape string.
123-
b := S2B(s) // It is safe to do, since s points to a byte slice in Parser.b.
123+
b := []byte(s) // It is safe to do, since s points to a byte slice in Parser.b.
124124
b = b[:n]
125125
s = s[n+1:]
126126
for len(s) > 0 {
@@ -190,7 +190,7 @@ func UnescapeJSONString(s string) string {
190190
b = append(b, s[:n]...)
191191
s = s[n+1:]
192192
}
193-
return B2S(b)
193+
return string(b)
194194
}
195195

196196
func EscapeJSONString(src string) string {

utils/strconv.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)