Use %q instead of "%s"

This commit is contained in:
jvoisin 2024-02-29 00:27:39 +01:00 committed by Frédéric Guillot
parent 5e5cb056c5
commit b04550e2f2
8 changed files with 8 additions and 8 deletions

View file

@ -107,7 +107,7 @@ type Subscription struct {
}
func (s Subscription) String() string {
return fmt.Sprintf(`Title="%s", URL="%s", Type="%s"`, s.Title, s.URL, s.Type)
return fmt.Sprintf(`Title=%q, URL=%q, Type=%q`, s.Title, s.URL, s.Type)
}
// Subscriptions represents a list of subscriptions.

View file

@ -28,7 +28,7 @@ func PushEntries(feed *model.Feed, entries model.Entries, matrixBaseURL, matrixU
for _, entry := range entries {
textMessages = append(textMessages, fmt.Sprintf(`[%s] %s - %s`, feed.Title, entry.Title, entry.URL))
formattedTextMessages = append(formattedTextMessages, fmt.Sprintf(`<li><strong>%s</strong>: <a href="%s">%s</a></li>`, feed.Title, entry.URL, entry.Title))
formattedTextMessages = append(formattedTextMessages, fmt.Sprintf(`<li><strong>%s</strong>: <a href=%q>%s</a></li>`, feed.Title, entry.URL, entry.Title))
}
_, err = client.SendFormattedTextMessage(

View file

@ -67,5 +67,5 @@ type Session struct {
}
func (s *Session) String() string {
return fmt.Sprintf(`ID="%s", Data={%v}`, s.ID, s.Data)
return fmt.Sprintf(`ID=%q, Data={%v}`, s.ID, s.Data)
}

View file

@ -21,7 +21,7 @@ type UserSession struct {
}
func (u *UserSession) String() string {
return fmt.Sprintf(`ID="%d", UserID="%d", IP="%s", Token="%s"`, u.ID, u.UserID, u.IP, u.Token)
return fmt.Sprintf(`ID=%q, UserID=%q, IP=%q, Token=%q`, u.ID, u.UserID, u.IP, u.Token)
}
// UseTimezone converts creation date to the given timezone.

View file

@ -292,7 +292,7 @@ func addInvidiousVideo(entryURL, entryContent string) string {
func addPDFLink(entryURL, entryContent string) string {
if strings.HasSuffix(entryURL, ".pdf") {
return fmt.Sprintf(`<a href="%s">PDF</a><br>%s`, entryURL, entryContent)
return fmt.Sprintf(`<a href=%q>PDF</a><br>%s`, entryURL, entryContent)
}
return entryContent
}

View file

@ -154,7 +154,7 @@ func sanitizeAttributes(baseURL, tagName string, attributes []html.Attribute) ([
}
attrNames = append(attrNames, attribute.Key)
htmlAttrs = append(htmlAttrs, fmt.Sprintf(`%s="%s"`, attribute.Key, html.EscapeString(value)))
htmlAttrs = append(htmlAttrs, fmt.Sprintf(`%s=%q`, attribute.Key, html.EscapeString(value)))
}
if !isAnchorLink {

View file

@ -17,7 +17,7 @@ func NewSubscription(title, url, kind string) *Subscription {
}
func (s Subscription) String() string {
return fmt.Sprintf(`Title="%s", URL="%s", Type="%s"`, s.Title, s.URL, s.Type)
return fmt.Sprintf(`Title=%q, URL=%q, Type=%q`, s.Title, s.URL, s.Type)
}
// Subscriptions represents a list of subscription.

View file

@ -27,7 +27,7 @@ func (h *handler) showJavascript(w http.ResponseWriter, r *http.Request) {
contents := static.JavascriptBundles[filename]
if filename == "service-worker" {
variables := fmt.Sprintf(`const OFFLINE_URL="%s";`, route.Path(h.router, "offline"))
variables := fmt.Sprintf(`const OFFLINE_URL=%q;`, route.Path(h.router, "offline"))
contents = append([]byte(variables)[:], contents[:]...)
}