Skip to content

Commit

Permalink
fix: check for upcase string as file
Browse files Browse the repository at this point in the history
Signed-off-by: gfanton <[email protected]>
  • Loading branch information
gfanton committed Jan 6, 2025
1 parent c51ec01 commit 62b005a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 9 additions & 4 deletions gno.land/pkg/gnoweb/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,16 @@ func ParseGnoURL(u *url.URL) (*GnoURL, error) {
}

var file string
if ext := filepath.Ext(upath); ext != "" {
file = filepath.Base(upath)
upath = strings.TrimSuffix(upath, file)

// Trim last slash
// A file is considered as one that either ends with an extension or
// contains an uppercase rune
ext := filepath.Ext(upath)
base := filepath.Base(upath)
if ext != "" || strings.ToLower(base) != base {
file = base
upath = strings.TrimSuffix(upath, base)

// Trim last slash if any
if i := strings.LastIndexByte(upath, '/'); i > 0 {
upath = upath[:i]
}
Expand Down
13 changes: 13 additions & 0 deletions gno.land/pkg/gnoweb/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,19 @@ func TestParseGnoURL(t *testing.T) {
Domain: "gno.land",
},
},

{
Name: "no extension file",
Input: "https://gno.land/r/demo/lIcEnSe",
Expected: &GnoURL{
Path: "/r/demo",
File: "lIcEnSe",
Args: "",
WebQuery: url.Values{},
Query: url.Values{},
Domain: "gno.land",
},
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 62b005a

Please sign in to comment.