Skip to content

Commit

Permalink
fix asset paths/URLs becoming lowercased (#988)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Suraci <[email protected]>
  • Loading branch information
vito authored Oct 10, 2024
1 parent dd6599e commit ccd75fb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/app/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,19 +854,19 @@ func parseHTTPResource(v string) httpResource {
if elem = strings.TrimSpace(elem); elem == "" {
continue
}
elem = strings.ToLower(elem)
lower := strings.ToLower(elem)

switch {
case elem == "crossorigin":
case lower == "crossorigin":
res.CrossOrigin = "true"

case strings.HasPrefix(elem, "crossorigin="):
res.CrossOrigin = strings.TrimPrefix(elem, "crossorigin=")
case strings.HasPrefix(lower, "crossorigin="):
res.CrossOrigin = strings.TrimPrefix(lower, "crossorigin=")

case elem == "defer":
case lower == "defer":
res.LoadingMode = "defer"

case elem == "async":
case lower == "async":
res.LoadingMode = "async"

default:
Expand Down
43 changes: 43 additions & 0 deletions pkg/app/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,49 @@ func TestHandlerServePageWithLocalDir(t *testing.T) {
t.Log(body)
}

func TestHandlerPreservesURLCasing(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/", nil)
w := httptest.NewRecorder()

h := Handler{
Resources: LocalDir(""),
Title: "Handler testing",
Scripts: []string{
"web/Hello.js",
"http://boo.com/Bar.js",
},
Styles: []string{
"web/Foo.css",
"/web/Bar.css",
"https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded",
},
RawHeaders: []string{
`<meta http-equiv="refresh" content="30">`,
},
Image: "/web/test.png",
}
h.Icon.Maskable = "ios.png"

h.ServeHTTP(w, r)

body := w.Body.String()
require.Equal(t, http.StatusOK, w.Code)
require.Contains(t, body, `<html lang="en">`)
require.Contains(t, body, `href="/web/Foo.css"`)
require.Contains(t, body, `href="/web/Bar.css"`)
require.Contains(t, body, `href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded"`)
require.Contains(t, body, `src="/web/Hello.js"`)
require.Contains(t, body, `src="http://boo.com/Bar.js"`)
require.Contains(t, body, `href="/manifest.webmanifest"`)
require.Contains(t, body, `href="/app.css"`)
require.Contains(t, body, `<meta http-equiv="refresh" content="30">`)
require.Contains(t, body, `<div id="pre-render-ok">`)
require.Contains(t, body, `content="https:///web/test.png"`)
require.Contains(t, body, `<img src="/web/resolve-static-resource-test.jpg">`)

t.Log(body)
}

func TestHandlerServePageWithRemoteBucket(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/", nil)
w := httptest.NewRecorder()
Expand Down

0 comments on commit ccd75fb

Please sign in to comment.