Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _runtime/pushup_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func regexPatFromRoute(route string) routePat {
out = append(out, match)
slugs = append(slugs, sub[1:])
} else {
out = append(out, sub)
out = append(out, regexp.QuoteMeta(sub))
}
}
return routePat{strings.Join(out, "/"), slugs}
Expand Down
27 changes: 27 additions & 0 deletions _runtime/pushup_support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ func TestRegexPatFromRoute(t *testing.T) {
"/:foo/bar/:quux",
routePat{"/([^/]+)/bar/([^/]+)", []string{"foo", "quux"}},
},
{
"/.well-known/openid-configuration",
routePat{"/\\.well-known/openid-configuration", nil},
},
{
"/.well-known",
routePat{"/\\.well-known", nil},
},
}

for _, test := range tests {
Expand Down Expand Up @@ -206,3 +214,22 @@ func TestMatchURLPathSegmentPrefix(t *testing.T) {
})
}
}

func TestRoutePeriodSegment(t *testing.T) {
savedRoutes := routes
defer func() { routes = savedRoutes }()

routes = routeList{}
dummy := new(dummyPage)
routes.add("/.well-known/openid-configuration", dummy, routePage)

m1 := getRouteFromPath("/.well-known/openid-configuration")
if m1.response != routeFound {
t.Errorf("expected routeFound for /.well-known/openid-configuration, got %v", m1.response)
}

m2 := getRouteFromPath("/xwell-known/openid-configuration")
if m2.response != routeNotFound {
t.Errorf("expected routeNotFound for /xwell-known/openid-configuration, got %v", m2.response)
}
}
20 changes: 16 additions & 4 deletions codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,11 @@ func routeForPage(relpath string) string {
dirs = strings.Split(dir, string([]rune{os.PathSeparator}))
}
file := filepath.Base(relpath)
base := strings.TrimSuffix(file, filepath.Ext(file))
ext := filepath.Ext(file)
base := file
if ext != "" && ext != file {
base = strings.TrimSuffix(file, ext)
}
var route string
if base != "index" {
dirs = append(dirs, base)
Expand All @@ -700,7 +704,11 @@ func routeForPage(relpath string) string {
}

func routeForPartial(relpath string, partialUrlpath string) string {
prefix := strings.TrimSuffix(relpath, filepath.Ext(relpath))
ext := filepath.Ext(relpath)
prefix := relpath
if ext != "" && ext != relpath && ext != filepath.Base(relpath) {
prefix = strings.TrimSuffix(relpath, ext)
}
if filepath.Base(prefix) == "index" {
prefix = filepath.Dir(prefix)
}
Expand Down Expand Up @@ -951,7 +959,9 @@ func genCodePage(g *pageCodeGen) ([]byte, error) {
func generatedTypename(pfile projectFile, ftype upFileType) string {
relpath := pfile.relpath()
ext := filepath.Ext(relpath)
relpath = relpath[:len(relpath)-len(ext)]
if ext != "" && ext != relpath && ext != filepath.Base(relpath) {
relpath = relpath[:len(relpath)-len(ext)]
}
typename := typenameFromPath(relpath)
var suffix string
switch ftype {
Expand All @@ -969,7 +979,9 @@ func generatedTypename(pfile projectFile, ftype upFileType) string {
func generatedTypenamePartial(partial *partial, pfile projectFile) string {
relpath := pfile.relpath()
ext := filepath.Ext(relpath)
relpath = relpath[:len(relpath)-len(ext)]
if ext != "" && ext != relpath && ext != filepath.Base(relpath) {
relpath = relpath[:len(relpath)-len(ext)]
}
typename := typenameFromPath(strings.Join([]string{relpath, partial.urlpath()}, "/"))
result := typename + "Partial"
return result
Expand Down
18 changes: 18 additions & 0 deletions codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ func TestRouteForPage(t *testing.T) {
"blah/index.up",
"/blah/",
},
{
".well-known/openid-configuration.up",
"/.well-known/openid-configuration",
},
{
".well-known",
"/.well-known",
},
{
".well-known.up",
"/.well-known",
},
{
".well-known/index.up",
"/.well-known/",
},
}

for _, test := range tests {
Expand All @@ -104,6 +120,8 @@ func TestGeneratedTypename(t *testing.T) {
{projectFile{path: "foo_bar.up", projectFilesSubdir: "."}, upFilePage, "FooBarPage"},
{projectFile{path: "a/b/c.up", projectFilesSubdir: "."}, upFilePage, "ABCPage"},
{projectFile{path: "a/b/$c.up", projectFilesSubdir: "."}, upFilePage, "ABDollarSignCPage"},
{projectFile{path: ".well-known/openid-configuration.up", projectFilesSubdir: "."}, upFilePage, "WellKnownOpenidConfigurationPage"},
{projectFile{path: ".well-known.up", projectFilesSubdir: "."}, upFilePage, "WellKnownPage"},
}

for _, test := range tests {
Expand Down
29 changes: 24 additions & 5 deletions compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,36 @@ func compiledOutputPath(pfile projectFile, ftype upFileType) string {
if err != nil {
panic("internal error: relative path from project files subdir to .up file: " + err.Error())
}
// a .go file with a leading '$' in the name is invalid to the go tool
if rel[0] == '$' {
rel = "0x24" + rel[1:]
}
var dirs []string
dir := filepath.Dir(rel)
if dir != "." {
dirs = strings.Split(dir, string([]rune{os.PathSeparator}))
}
file := filepath.Base(rel)
base := strings.TrimSuffix(file, filepath.Ext(file))
ext := filepath.Ext(file)
base := file
if ext != "" && ext != file {
base = strings.TrimSuffix(file, ext)
}

mangle := func(s string) string {
if strings.HasPrefix(s, "$") {
return "0x24" + s[1:]
}
if strings.HasPrefix(s, ".") {
return "0x2e" + s[1:]
}
if strings.HasPrefix(s, "_") {
return "0x5f" + s[1:]
}
return s
}

for i := range dirs {
dirs[i] = mangle(dirs[i])
}
base = mangle(base)

suffix := upFileExt
if ftype == upFileLayout {
suffix = ".layout.up"
Expand Down
15 changes: 15 additions & 0 deletions compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ func TestCompiledOutputPath(t *testing.T) {
"0x24foo.up.go",
upFilePage,
},
{
projectFile{path: "app/pages/.well-known/openid-configuration.up", projectFilesSubdir: "app/pages"},
"0x2ewell-known__openid-configuration.up.go",
upFilePage,
},
{
projectFile{path: "app/pages/.well-known.up", projectFilesSubdir: "app/pages"},
"0x2ewell-known.up.go",
upFilePage,
},
{
projectFile{path: "app/pages/sub/.well-known/openid-configuration.up", projectFilesSubdir: "app/pages"},
"sub__0x2ewell-known__openid-configuration.up.go",
upFilePage,
},
}

for _, test := range tests {
Expand Down