Skip to content
代码片段 群组 项目
提交 3b3a5e59 编辑于 作者: charlie ablett's avatar charlie ablett
浏览文件

Merge branch 'qmnguyen0711/fix-expand-path-owner-home-directory' into 'master'

Fix Wiki feature raises exception when titles start with ~

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/100567



Merged-by: default avatarcharlie ablett <cablett@gitlab.com>
Approved-by: default avatarChad Woolley <cwoolley@gitlab.com>
Approved-by: default avatarcharlie ablett <cablett@gitlab.com>
Approved-by: default avatarDominic Couture <dcouture@gitlab.com>
Co-authored-by: default avatarQuang-Minh Nguyen <qmnguyen@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -109,8 +109,8 @@ def sluggified_full_path(title, extension) ...@@ -109,8 +109,8 @@ def sluggified_full_path(title, extension)
end end
def sluggified_title(title) def sluggified_title(title)
title = Gitlab::EncodingHelper.encode_utf8_no_detect(title) title = Gitlab::EncodingHelper.encode_utf8_no_detect(title.to_s.strip)
title = File.expand_path(title, '/') title = File.absolute_path(title, '/')
title = Pathname.new(title).relative_path_from('/').to_s title = Pathname.new(title).relative_path_from('/').to_s
title.tr(' ', '-') title.tr(' ', '-')
end end
......
...@@ -374,6 +374,39 @@ def total_pages(entries) ...@@ -374,6 +374,39 @@ def total_pages(entries)
end end
end end
context 'pages with relative paths' do
where(:path, :title) do
[
['~hello.md', '~Hello'],
['hello~world.md', 'Hello~World'],
['~~~hello.md', '~~~Hello'],
['~/hello.md', '~/Hello'],
['hello.md', '/Hello'],
['hello.md', '../Hello'],
['hello.md', './Hello'],
['dir/hello.md', '/dir/Hello']
]
end
with_them do
before do
wiki.repository.create_file(
user, path, "content of wiki file",
branch_name: wiki.default_branch,
message: "created page #{path}",
author_email: user.email,
author_name: user.name
)
end
it "can find page with `#{params[:title]}` title" do
page = subject.find_page(title)
expect(page.content).to eq("content of wiki file")
end
end
end
context 'pages with different file extensions' do context 'pages with different file extensions' do
where(:extension, :path, :title) do where(:extension, :path, :title) do
[ [
...@@ -629,6 +662,8 @@ def total_pages(entries) ...@@ -629,6 +662,8 @@ def total_pages(entries)
'foo' | :org | ['foo.md'] | false 'foo' | :org | ['foo.md'] | false
'foo' | :markdown | ['dir/foo.md'] | true 'foo' | :markdown | ['dir/foo.md'] | true
'/foo' | :markdown | ['foo.md'] | false '/foo' | :markdown | ['foo.md'] | false
'~foo' | :markdown | [] | true
'~~~foo' | :markdown | [] | true
'./foo' | :markdown | ['foo.md'] | false './foo' | :markdown | ['foo.md'] | false
'../foo' | :markdown | ['foo.md'] | false '../foo' | :markdown | ['foo.md'] | false
'../../foo' | :markdown | ['foo.md'] | false '../../foo' | :markdown | ['foo.md'] | false
...@@ -739,6 +774,8 @@ def update_page ...@@ -739,6 +774,8 @@ def update_page
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
where(:original_title, :original_format, :updated_title, :updated_format, :expected_title, :expected_path) do where(:original_title, :original_format, :updated_title, :updated_format, :expected_title, :expected_path) do
'test page' | :markdown | '~new test page' | :asciidoc | '~new test page' | '~new-test-page.asciidoc'
'test page' | :markdown | '~~~new test page' | :asciidoc | '~~~new test page' | '~~~new-test-page.asciidoc'
'test page' | :markdown | 'new test page' | :asciidoc | 'new test page' | 'new-test-page.asciidoc' 'test page' | :markdown | 'new test page' | :asciidoc | 'new test page' | 'new-test-page.asciidoc'
'test page' | :markdown | 'new dir/new test page' | :asciidoc | 'new dir/new test page' | 'new-dir/new-test-page.asciidoc' 'test page' | :markdown | 'new dir/new test page' | :asciidoc | 'new dir/new test page' | 'new-dir/new-test-page.asciidoc'
'test dir/test page' | :markdown | 'new dir/new test page' | :asciidoc | 'new dir/new test page' | 'new-dir/new-test-page.asciidoc' 'test dir/test page' | :markdown | 'new dir/new test page' | :asciidoc | 'new dir/new test page' | 'new-dir/new-test-page.asciidoc'
...@@ -748,13 +785,13 @@ def update_page ...@@ -748,13 +785,13 @@ def update_page
'test dir/test page' | :markdown | nil | :markdown | 'test dir/test page' | 'test-dir/test-page.md' 'test dir/test page' | :markdown | nil | :markdown | 'test dir/test page' | 'test-dir/test-page.md'
'test page' | :markdown | '' | :markdown | 'test page' | 'test-page.md' 'test page' | :markdown | '' | :markdown | 'test page' | 'test-page.md'
'test.page' | :markdown | '' | :markdown | 'test.page' | 'test.page.md' 'test.page' | :markdown | '' | :markdown | 'test.page' | 'test.page.md'
'testpage' | :markdown | '../testpage' | :markdown | 'testpage' | 'testpage.md' 'testpage' | :markdown | '../testpage' | :markdown | 'testpage' | 'testpage.md'
'dir/testpage' | :markdown | 'dir/../testpage' | :markdown | 'testpage' | 'testpage.md' 'dir/testpage' | :markdown | 'dir/../testpage' | :markdown | 'testpage' | 'testpage.md'
'dir/testpage' | :markdown | './dir/testpage' | :markdown | 'dir/testpage' | 'dir/testpage.md' 'dir/testpage' | :markdown | './dir/testpage' | :markdown | 'dir/testpage' | 'dir/testpage.md'
'dir/testpage' | :markdown | '../dir/testpage' | :markdown | 'dir/testpage' | 'dir/testpage.md' 'dir/testpage' | :markdown | '../dir/testpage' | :markdown | 'dir/testpage' | 'dir/testpage.md'
'dir/testpage' | :markdown | '../dir/../testpage' | :markdown | 'testpage' | 'testpage.md' 'dir/testpage' | :markdown | '../dir/../testpage' | :markdown | 'testpage' | 'testpage.md'
'dir/testpage' | :markdown | '../dir/../dir/testpage' | :markdown | 'dir/testpage' | 'dir/testpage.md' 'dir/testpage' | :markdown | '../dir/../dir/testpage' | :markdown | 'dir/testpage' | 'dir/testpage.md'
'dir/testpage' | :markdown | '../dir/../another/testpage' | :markdown | 'another/testpage' | 'another/testpage.md' 'dir/testpage' | :markdown | '../dir/../another/testpage' | :markdown | 'another/testpage' | 'another/testpage.md'
end end
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册