Skip to content

Fix duplicate path fragments from PathCleaner.clean #2150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/services/path_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def self.clean(uri, constant:, version:)
uri.path.delete_suffix(".html").split("/").each do |path_part|
if path_part == ".."
class_parts.pop
else
elsif !class_parts.include?(path_part)
class_parts.push(path_part)
end
end
Expand Down
54 changes: 54 additions & 0 deletions test/services/path_cleaner_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

require "test_helper"

class PathCleanerTest < ActiveSupport::TestCase
test "clean relative uris with constant" do
assert_object_param "fiber", PathCleaner.clean(make_uri("../Fiber"), constant: "Fiber::SchedulerInterface", version: "1.0")
assert_object_param(
"rubyvm/abstractsyntaxtree",
PathCleaner.clean(make_uri("../AbstractSyntaxTree"), constant: "RubyVM::AbstractSyntaxTree::Node", version: "1.0")
)
end

test "clean path full path with nested constant" do
assert_object_param(
"thread/queue",
PathCleaner.clean(make_uri("Thread/Queue"), constant: "Thread::Queue", version: "1.0")
)
assert_object_param(
"csv/row",
PathCleaner.clean(make_uri("CSV/Row"), constant: "CSV::Row", version: "1.0")
)
end

test "clean path partial path with nested constant" do
assert_object_param(
"rubyvm/abstractsyntaxtree/node",
PathCleaner.clean(make_uri("Node"), constant: "RubyVM::AbstractSyntaxTree::Node", version: "1.0")
)
end

test "clean path with unrelated constant" do
assert_object_param(
"enumerator/arithmeticsequence",
PathCleaner.clean(make_uri("Enumerator/Arithmeticsequence"), constant: "String", version: "1.0")
)

assert_object_param(
"io",
PathCleaner.clean(make_uri("../IO"), constant: "Fiber::SchedulerInterface", version: "1.0")
)
end

private

def assert_object_param(expected, uri_string)
uri = URI(uri_string)
assert_equal expected, uri.path.split("/")[3..].join("/")
end

def make_uri(path)
URI("#{path}.html")
end
end