Skip to content
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

Return binary git paths, not potentially invalid UTF8 #936

Open
wants to merge 1 commit into
base: master
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 ext/rugged/rugged.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ VALUE rb_merge_file_result_fromC(const git_merge_file_result *result)
VALUE rb_result = rb_hash_new();

rb_hash_aset(rb_result, CSTR2SYM("automergeable"), result->automergeable ? Qtrue : Qfalse);
rb_hash_aset(rb_result, CSTR2SYM("path"), result->path ? rb_str_new_utf8(result->path) : Qnil);
rb_hash_aset(rb_result, CSTR2SYM("path"), result->path ? rb_str_new2(result->path) : Qnil);
rb_hash_aset(rb_result, CSTR2SYM("filemode"), INT2FIX(result->mode));
rb_hash_aset(rb_result, CSTR2SYM("data"), rb_str_new(result->ptr, result->len));

Expand Down
2 changes: 1 addition & 1 deletion ext/rugged/rugged_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ static VALUE rb_git_indexentry_fromC(const git_index_entry *entry)

rb_entry = rb_hash_new();

rb_hash_aset(rb_entry, CSTR2SYM("path"), rb_str_new_utf8(entry->path));
rb_hash_aset(rb_entry, CSTR2SYM("path"), rb_str_new2(entry->path));
rb_hash_aset(rb_entry, CSTR2SYM("oid"), rugged_create_oid(&entry->id));

rb_hash_aset(rb_entry, CSTR2SYM("dev"), INT2FIX(entry->dev));
Expand Down
2 changes: 1 addition & 1 deletion ext/rugged/rugged_submodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ static VALUE rb_git_submodule_path(VALUE self)

path = git_submodule_path(submodule);

return rb_str_new_utf8(path);
return rb_str_new2(path);
}

#define RB_GIT_OID_GETTER(_klass, _attribute) \
Expand Down
2 changes: 1 addition & 1 deletion ext/rugged/rugged_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static VALUE rb_git_treeentry_fromC(const git_tree_entry *entry)

rb_entry = rb_hash_new();

rb_hash_aset(rb_entry, CSTR2SYM("name"), rb_str_new_utf8(git_tree_entry_name(entry)));
rb_hash_aset(rb_entry, CSTR2SYM("name"), rb_str_new2(git_tree_entry_name(entry)));
rb_hash_aset(rb_entry, CSTR2SYM("oid"), rugged_create_oid(git_tree_entry_id(entry)));

rb_hash_aset(rb_entry, CSTR2SYM("filemode"), INT2FIX(git_tree_entry_filemode(entry)));
Expand Down
11 changes: 11 additions & 0 deletions test/index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ def test_conflicts
assert_equal 3, conflicts[1][:theirs][:stage]
end

def test_conflict_paths_are_binary_encoded
conflicts = @repo.index.conflicts

assert_equal 2, conflicts.size
conflicts.each do |conflict|
conflict.each do |type, data|
assert_equal Encoding::BINARY, data[:path].encoding
end
end
end

def test_conflict_get
conflict = @repo.index.conflict_get("conflicts-one.txt")

Expand Down