Skip to content

Commit

Permalink
feat: prevent accidental invalid paths
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Gleich <[email protected]>
  • Loading branch information
gleich committed Dec 2, 2024
1 parent 8d9dbbf commit ba5819d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion internal/apis/applemusic/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package applemusic
import (
"fmt"
"net/http"
"strings"

"github.com/gleich/lcp-v2/internal/apis"
"github.com/gleich/lcp-v2/internal/secrets"
Expand All @@ -11,7 +12,11 @@ import (

func sendAppleMusicAPIRequest[T any](path string) (T, error) {
var zeroValue T
req, err := http.NewRequest("GET", fmt.Sprintf("https://api.music.apple.com%s", path), nil)
req, err := http.NewRequest(
"GET",
fmt.Sprintf("https://api.music.apple.com/%s", strings.TrimLeft(path, "/")),
nil,
)
if err != nil {
lumber.Error(err, "failed to create request")
return zeroValue, err
Expand Down
7 changes: 6 additions & 1 deletion internal/apis/strava/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package strava
import (
"fmt"
"net/http"
"strings"

"github.com/gleich/lcp-v2/internal/apis"
"github.com/gleich/lumber/v3"
Expand All @@ -11,7 +12,11 @@ import (
func sendStravaAPIRequest[T any](path string, tokens tokens) (T, error) {
var zeroValue T

req, err := http.NewRequest("GET", fmt.Sprintf("https://www.strava.com/%s", path), nil)
req, err := http.NewRequest(
"GET",
fmt.Sprintf("https://www.strava.com/%s", strings.TrimLeft(path, "/")),
nil,
)
if err != nil {
lumber.Error(err, "failed to create request")
return zeroValue, err
Expand Down

0 comments on commit ba5819d

Please sign in to comment.