Skip to content

Commit 3c5dd96

Browse files
author
Ændrew Rininsland
committed
Merge pull request github-tools#185 from ele828/master
Support Chinese file names. Thanks @ele828!
2 parents c2696ec + 6ada6cc commit 3c5dd96

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

github.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@
521521
// --------
522522

523523
this.contents = function(ref, path, cb) {
524+
path = encodeURI(path);
524525
_request("GET", repoPath + "/contents" + (path ? "/" + path : ""), { ref: ref }, cb);
525526
};
526527

@@ -595,7 +596,7 @@
595596
// -------
596597

597598
this.read = function(branch, path, cb) {
598-
_request("GET", repoPath + "/contents/"+path, {ref: branch}, function(err, obj) {
599+
_request("GET", repoPath + "/contents/"+encodeURI(path), {ref: branch}, function(err, obj) {
599600
if (err && err.error === 404) return cb("not found", null, null);
600601

601602
if (err) return cb(err);
@@ -663,9 +664,9 @@
663664
// -------
664665

665666
this.write = function(branch, path, content, message, cb) {
666-
that.getSha(branch, path, function(err, sha) {
667+
that.getSha(branch, encodeURI(path), function(err, sha) {
667668
if (err && err.error !== 404) return cb(err);
668-
_request("PUT", repoPath + "/contents/" + path, {
669+
_request("PUT", repoPath + "/contents/" + encodeURI(path), {
669670
message: message,
670671
content: btoa(content),
671672
branch: branch,

test/test.repo.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ test('Create Repo', function(t) {
103103
q.end();
104104
});
105105
});
106+
107+
t.test('repo.writeChinese', function(q) {
108+
repo.write('master', '中文测试.md', 'THIS IS A TEST', 'Creating test', function(err) {
109+
q.error(err);
110+
q.end();
111+
});
112+
});
106113
clearTimeout(timeout);
107114
t.end();
108115
});

0 commit comments

Comments
 (0)