diff options
author | Stan Hu <stanhu@gmail.com> | 2018-03-23 22:19:55 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-03-23 22:19:55 +0300 |
commit | 8cdd3a6b54d1f728378e0810d88f79a2effe87b7 (patch) | |
tree | cec56aae1952624ec1330a6ecc5fd2993f5f5242 /spec | |
parent | 9af61b3fe3192df0deaf05597643efb8d0630eba (diff) | |
parent | 70af1e2e03c031105117596e398f82dee4ae61a4 (diff) |
Merge branch '44564-error-500-while-attempting-to-resolve-conflicts-due-to-utf-8-conversion-error' into 'master'
Resolve "Error 500 while attempting to resolve conflicts due to UTF-8 conversion error"
Closes #44564
See merge request gitlab-org/gitlab-ce!17962
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/git/conflict/file_spec.rb | 50 | ||||
-rw-r--r-- | spec/lib/gitlab/git/conflict/parser_spec.rb | 7 |
2 files changed, 50 insertions, 7 deletions
diff --git a/spec/lib/gitlab/git/conflict/file_spec.rb b/spec/lib/gitlab/git/conflict/file_spec.rb new file mode 100644 index 00000000000..afed6c32af6 --- /dev/null +++ b/spec/lib/gitlab/git/conflict/file_spec.rb @@ -0,0 +1,50 @@ +# coding: utf-8 +require 'spec_helper' + +describe Gitlab::Git::Conflict::File do + let(:conflict) { { theirs: { path: 'foo', mode: 33188 }, ours: { path: 'foo', mode: 33188 } } } + let(:invalid_content) { described_class.new(nil, nil, conflict, "a\xC4\xFC".force_encoding(Encoding::ASCII_8BIT)) } + let(:valid_content) { described_class.new(nil, nil, conflict, "Espa\xC3\xB1a".force_encoding(Encoding::ASCII_8BIT)) } + + describe '#lines' do + context 'when the content contains non-UTF-8 characters' do + it 'raises UnsupportedEncoding' do + expect { invalid_content.lines } + .to raise_error(described_class::UnsupportedEncoding) + end + end + + context 'when the content can be converted to UTF-8' do + it 'sets lines to the lines' do + expect(valid_content.lines).to eq([{ + full_line: 'España', + type: nil, + line_obj_index: 0, + line_old: 1, + line_new: 1 + }]) + end + + it 'sets the type to text' do + expect(valid_content.type).to eq('text') + end + end + end + + describe '#content' do + context 'when the content contains non-UTF-8 characters' do + it 'raises UnsupportedEncoding' do + expect { invalid_content.content } + .to raise_error(described_class::UnsupportedEncoding) + end + end + + context 'when the content can be converted to UTF-8' do + it 'returns a valid UTF-8 string' do + expect(valid_content.content).to eq('España') + expect(valid_content.content).to be_valid_encoding + expect(valid_content.content.encoding).to eq(Encoding::UTF_8) + end + end + end +end diff --git a/spec/lib/gitlab/git/conflict/parser_spec.rb b/spec/lib/gitlab/git/conflict/parser_spec.rb index 7b035a381f1..29a1702a1c6 100644 --- a/spec/lib/gitlab/git/conflict/parser_spec.rb +++ b/spec/lib/gitlab/git/conflict/parser_spec.rb @@ -212,13 +212,6 @@ CONFLICT .not_to raise_error end end - - context 'when the file contains non-UTF-8 characters' do - it 'raises UnsupportedEncoding' do - expect { parse_text("a\xC4\xFC".force_encoding(Encoding::ASCII_8BIT)) } - .to raise_error(Gitlab::Git::Conflict::Parser::UnsupportedEncoding) - end - end end end end |