mirror of
https://github.com/jetzig-framework/jetzig.git
synced 2025-05-14 14:06:08 +00:00
Strip trailing slash on URIs
`/blogs/` is now the same as `/blogs`. Root path `/` is a special case.
This commit is contained in:
parent
c8ae44b508
commit
c5acaedb73
@ -7,8 +7,8 @@
|
|||||||
.hash = "1220d0e8734628fd910a73146e804d10a3269e3e7d065de6bb0e3e88d5ba234eb163",
|
.hash = "1220d0e8734628fd910a73146e804d10a3269e3e7d065de6bb0e3e88d5ba234eb163",
|
||||||
},
|
},
|
||||||
.zmpl = .{
|
.zmpl = .{
|
||||||
.url = "https://github.com/jetzig-framework/zmpl/archive/517b453f333c328ff5ebafa49020b1040e54e880.tar.gz",
|
.url = "https://github.com/jetzig-framework/zmpl/archive/369193322cc572197b57a1a2cebd85b317bf92c4.tar.gz",
|
||||||
.hash = "1220798a4647e3b0766aad653830a2601e11c567ba6bfe83e526eb91d04a6c45f7d8",
|
.hash = "12205982592aa38f37bba8d7410f62263827a49b350c1029a2eb79e8cc12b7247e9c",
|
||||||
},
|
},
|
||||||
.jetkv = .{
|
.jetkv = .{
|
||||||
.url = "https://github.com/jetzig-framework/jetkv/archive/2b1130a48979ea2871c8cf6ca89c38b1e7062839.tar.gz",
|
.url = "https://github.com/jetzig-framework/jetkv/archive/2b1130a48979ea2871c8cf6ca89c38b1e7062839.tar.gz",
|
||||||
|
@ -92,9 +92,9 @@ fn getBasePath(path: []const u8) []const u8 {
|
|||||||
return path[0..query_index];
|
return path[0..query_index];
|
||||||
}
|
}
|
||||||
} else if (std.mem.lastIndexOfScalar(u8, path, '.')) |extension_index| {
|
} else if (std.mem.lastIndexOfScalar(u8, path, '.')) |extension_index| {
|
||||||
return path[0..extension_index];
|
return if (std.mem.eql(u8, path, "/")) path else std.mem.trimRight(u8, path[0..extension_index], "/");
|
||||||
} else {
|
} else {
|
||||||
return path;
|
return if (std.mem.eql(u8, path, "/")) path else std.mem.trimRight(u8, path, "/");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,6 +181,18 @@ test ".base_path (without extension, without query)" {
|
|||||||
try std.testing.expectEqualStrings("/foo/bar/baz", path.base_path);
|
try std.testing.expectEqualStrings("/foo/bar/baz", path.base_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test ".base_path (with trailing slash)" {
|
||||||
|
const path = Self.init("/foo/bar/");
|
||||||
|
|
||||||
|
try std.testing.expectEqualStrings("/foo/bar", path.base_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
test ".base_path (root path)" {
|
||||||
|
const path = Self.init("/");
|
||||||
|
|
||||||
|
try std.testing.expectEqualStrings("/", path.base_path);
|
||||||
|
}
|
||||||
|
|
||||||
test ".directory (with extension, with query)" {
|
test ".directory (with extension, with query)" {
|
||||||
const path = Self.init("/foo/bar/baz.html?qux=quux&corge=grault");
|
const path = Self.init("/foo/bar/baz.html?qux=quux&corge=grault");
|
||||||
|
|
||||||
@ -229,6 +241,12 @@ test ".resource_id (without extension, without query, without base path)" {
|
|||||||
try std.testing.expectEqualStrings("baz", path.resource_id);
|
try std.testing.expectEqualStrings("baz", path.resource_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test ".resource_id (with trailing slash)" {
|
||||||
|
const path = Self.init("/foo/bar/");
|
||||||
|
|
||||||
|
try std.testing.expectEqualStrings("bar", path.resource_id);
|
||||||
|
}
|
||||||
|
|
||||||
test ".extension (with query)" {
|
test ".extension (with query)" {
|
||||||
const path = Self.init("/foo/bar/baz.html?qux=quux&corge=grault");
|
const path = Self.init("/foo/bar/baz.html?qux=quux&corge=grault");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user