@@ -326,3 +326,33 @@ def handler(req):
326326 _ , _ , err := CreateTestApp (logger , fileData )
327327 testutil .AssertErrorContains (t , err , "static_only app cannot have HTML routes" )
328328}
329+
330+ func TestRedirectBarePath (t * testing.T ) {
331+ logger := testutil .TestLogger ()
332+ fileData := map [string ]string {
333+ "app.star" : `
334+ app = ace.app("testApp", custom_layout=True, routes = [ace.html("/")], redirect_bare_path=True)
335+
336+ def handler(req):
337+ return {"key": "myvalue"}` ,
338+ "index.go.html" : `abc {{static "file1"}} def {{static "file2.txt"}}` ,
339+ }
340+
341+ a , _ , err := CreateTestApp (logger , fileData )
342+ if err != nil {
343+ t .Fatalf ("Error %s" , err )
344+ }
345+
346+ request := httptest .NewRequest ("GET" , "/test" , nil )
347+ response := httptest .NewRecorder ()
348+ a .ServeHTTP (response , request )
349+
350+ testutil .AssertEqualsInt (t , "code" , 307 , response .Code ) // redirect to the full path with trailing slash
351+ testutil .AssertStringContains (t , response .Header ().Get ("Location" ), "/test/" )
352+
353+ request = httptest .NewRequest ("GET" , "/test/" , nil )
354+ response = httptest .NewRecorder ()
355+ a .ServeHTTP (response , request )
356+
357+ testutil .AssertEqualsInt (t , "code" , 200 , response .Code ) // no redirect for the full path with trailing slash
358+ }
0 commit comments