Fix wiki encoding error creating event

Changelog: fixed
parent 5696f591
...@@ -66,7 +66,8 @@ module Git ...@@ -66,7 +66,8 @@ module Git
def strip_extension(filename) def strip_extension(filename)
return unless filename return unless filename
File.basename(filename, File.extname(filename)) encoded_filename = Gitlab::EncodingHelper.encode_utf8(filename.dup)
File.basename(encoded_filename, File.extname(encoded_filename))
end end
end end
end end
......
...@@ -64,6 +64,26 @@ RSpec.describe Git::WikiPushService, services: true do ...@@ -64,6 +64,26 @@ RSpec.describe Git::WikiPushService, services: true do
expect(Event.last(count).pluck(:action)).to match_array(Event::WIKI_ACTIONS.map(&:to_s)) expect(Event.last(count).pluck(:action)).to match_array(Event::WIKI_ACTIONS.map(&:to_s))
end end
context 'when wiki_page slug is not UTF-8 ' do
let(:binary_title) { Gitlab::EncodingHelper.encode_binary('编码') }
def run_service
wiki_page = create(:wiki_page, wiki: wiki, title: "#{binary_title} 'foo'")
process_changes do
# Test that new_path is converted to UTF-8
create(:wiki_page, wiki: wiki, title: binary_title)
# Test that old_path is also is converted to UTF-8
update_page(wiki_page.title, 'foo')
end
end
it 'does not raise an error' do
expect { run_service }.not_to raise_error
end
end
end end
context 'two pages have been created' do context 'two pages have been created' do
...@@ -345,9 +365,10 @@ RSpec.describe Git::WikiPushService, services: true do ...@@ -345,9 +365,10 @@ RSpec.describe Git::WikiPushService, services: true do
::Wikis::CreateAttachmentService.new(container: wiki.container, current_user: current_user, params: params).execute ::Wikis::CreateAttachmentService.new(container: wiki.container, current_user: current_user, params: params).execute
end end
def update_page(title) def update_page(title, new_title = nil)
new_title = title unless new_title.present?
page = git_wiki.page(title: title) page = git_wiki.page(title: title)
git_wiki.update_page(page.path, title, 'markdown', 'Hey', commit_details) git_wiki.update_page(page.path, new_title, 'markdown', 'Hey', commit_details)
end end
def delete_page(page) def delete_page(page)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment