Skip to content

Commit ca9b6e9

Browse files
Preserve root URL paths.
Assisted-By: devx/cbdeae41-9308-4071-ad53-58cd92db2946
1 parent 11ad459 commit ca9b6e9

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

lib/utopia/path.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ def to_str
224224
# Encode this application path as a URL path.
225225
# @returns [Protocol::URL::Path] The encoded URL path.
226226
def to_url_path
227+
# Preserve Utopia's compact representation of the absolute root:
228+
if @components == [""]
229+
return Protocol::URL::Path[SEPARATOR]
230+
end
231+
227232
return Protocol::URL::Path.for(
228233
@components,
229234
encoding: Protocol::URL::Encoding::System,

test/utopia/path.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@
140140
end
141141

142142
with "#to_url_path" do
143+
it "preserves the absolute root" do
144+
path = Utopia::Path.root
145+
146+
expect(path.to_url_path).to be == Protocol::URL::Path["/"]
147+
end
148+
143149
it "encodes application path components" do
144150
path = Utopia::Path.new(["", "some path"])
145151

0 commit comments

Comments
 (0)