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 4c45e1b commit c6e36df
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
15 changes: 10 additions & 5 deletions gno.land/pkg/gnoweb/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var ErrURLInvalidPath = errors.New("invalid path")

// rePkgOrRealmPath matches and validates a flexible path.
var rePkgOrRealmPath = regexp.MustCompile(`^/[a-zA-Z][a-zA-Z0-9_/]*$`)
var rePkgOrRealmPath = regexp.MustCompile(`^/[a-z][a-z0-9_/]*$`)

// GnoURL decomposes the parts of an URL to query a realm.
type GnoURL struct {
Expand Down 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 c6e36df

Please sign in to comment.