module
Noir::URLPath
Defined in:
utils/url_path.crClass Method Summary
-
.join(parent : String, child : String) : String
Join two URL path segments without introducing double slashes.
Class Method Detail
Join two URL path segments without introducing double slashes.
This method is designed for joining route prefixes and paths in web frameworks. It handles the common cases of trailing/leading slashes to produce clean URLs.
Behavior:
- If parent is empty, returns child as-is
- If child is empty, returns parent as-is
- If both have slashes at the join point, one is removed
- If neither has a slash at the join point, one is added
Examples: URLPath.join("/api", "/users") # => "/api/users" URLPath.join("/api/", "/users") # => "/api/users" URLPath.join("/api", "users") # => "/api/users" URLPath.join("", "/users") # => "/users" URLPath.join("/api", "") # => "/api" URLPath.join("/api", "/") # => "/api/"
Note: This does not normalize multiple consecutive slashes within paths. For example, URLPath.join("/api//v1", "users") produces "/api//v1/users".