Skip to content

Commit 948ea79

Browse files
Simplify original request paths.
Assisted-By: devx/cbdeae41-9308-4071-ad53-58cd92db2946
1 parent eee0b24 commit 948ea79

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

lib/utopia/request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def request_path
101101
# The original request path as decoded application components.
102102
# @returns [Utopia::Path] The normalized original request path.
103103
def original_path
104-
path = Protocol::URL::Path[self.request_path].normalize
104+
path = Protocol::URL::Path[self.request_path].normalize.simplify
105105
return Path.new(path.components(Protocol::URL::Encoding::System))
106106
end
107107

test/utopia/content/document.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
expect(document.request_path).to be == Utopia::Path["/index"]
2323
end
2424

25+
it "uses the normalized original request path" do
26+
request = Utopia::Request["GET", "/nested/../%69ndex"]
27+
document = subject.new(request, {})
28+
29+
request.path = "/rewritten"
30+
31+
expect(document.request_path).to be == Utopia::Path["/index"]
32+
end
33+
2534
it "should generate valid self-closing markup" do
2635
node = proc do |document, state|
2736
document.tag("img", src: "cats.jpg")

test/utopia/request.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838
expect(request.request_path).to be == "/search"
3939
end
4040

41+
it "normalizes and simplifies the original request path" do
42+
request = Utopia::Request["GET", "/nested/../%69ndex?key=value"]
43+
request.path = "/rewritten"
44+
45+
expect(request.original_path).to be == Utopia::Path["/index"]
46+
end
47+
4148
it "identifies POST requests" do
4249
expect(request.post?).to be == true
4350

0 commit comments

Comments
 (0)