@@ -357,7 +357,7 @@ pub const Cookie = struct {
357357 value = value [1.. ];
358358 }
359359
360- if (std .mem .indexOfScalarPos (u8 , value , 0 , '.' ) == null ) {
360+ if (std .mem .indexOfScalarPos (u8 , value , 0 , '.' ) == null and std . ascii . eqlIgnoreCase ( "localhost" , value ) == false ) {
361361 // can't set a cookie for a TLD
362362 return error .InvalidDomain ;
363363 }
@@ -838,6 +838,17 @@ test "Cookie: parse all" {
838838 .domain = ".lightpanda.io" ,
839839 .expires = std .time .timestamp () + 30 ,
840840 }, "https://lightpanda.io/cms/users" , "user-id=9000; HttpOnly; Max-Age=30; Secure; path=/; Domain=lightpanda.io" );
841+
842+ try expectCookie (.{
843+ .name = "app_session" ,
844+ .value = "123" ,
845+ .path = "/" ,
846+ .http_only = true ,
847+ .secure = false ,
848+ .domain = ".localhost" ,
849+ .same_site = .lax ,
850+ .expires = std .time .timestamp () + 7200 ,
851+ }, "http://localhost:8000/login" , "app_session=123; Max-Age=7200; path=/; domain=localhost; httponly; samesite=lax" );
841852}
842853
843854test "Cookie: parse domain" {
@@ -848,6 +859,8 @@ test "Cookie: parse domain" {
848859 try expectAttribute (.{ .domain = ".dev.lightpanda.io" }, "http://dev.lightpanda.io/" , "b;domain=dev.lightpanda.io" );
849860 try expectAttribute (.{ .domain = ".lightpanda.io" }, "http://dev.lightpanda.io/" , "b;domain=lightpanda.io" );
850861 try expectAttribute (.{ .domain = ".lightpanda.io" }, "http://dev.lightpanda.io/" , "b;domain=.lightpanda.io" );
862+ try expectAttribute (.{ .domain = ".localhost" }, "http://localhost/" , "b;domain=localhost" );
863+ try expectAttribute (.{ .domain = ".localhost" }, "http://localhost/" , "b;domain=.localhost" );
851864
852865 try expectError (error .InvalidDomain , "http://lightpanda.io/" , "b;domain=io" );
853866 try expectError (error .InvalidDomain , "http://lightpanda.io/" , "b;domain=.io" );
0 commit comments