Parcourir la source

Use `%q` instead of `"%s"`

jvoisin il y a 2 ans
Parent
commit
b04550e2f2

+ 1 - 1
client/model.go

@@ -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.

+ 1 - 1
internal/integration/matrixbot/matrixbot.go

@@ -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(

+ 1 - 1
internal/model/app_session.go

@@ -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)
 }

+ 1 - 1
internal/model/user_session.go

@@ -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.

+ 1 - 1
internal/reader/rewrite/rewrite_functions.go

@@ -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
 }

+ 1 - 1
internal/reader/sanitizer/sanitizer.go

@@ -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 {

+ 1 - 1
internal/reader/subscription/subscription.go

@@ -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.

+ 1 - 1
internal/ui/static_javascript.go

@@ -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[:]...)
 		}