+
Skip to content

Unicode content support #203

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

Merged
merged 1 commit into from
Oct 17, 2015
Merged
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
20 changes: 11 additions & 9 deletions github.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@
// Initial Setup
// -------------

var XMLHttpRequest, _, btoa;
var XMLHttpRequest, _, b64encode;
/* istanbul ignore else */
if (typeof exports !== 'undefined') {
XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
_ = require('underscore');
if (typeof btoa === 'undefined') {
btoa = require('btoa'); //jshint ignore:line
}
b64encode = require('js-base64').Base64.encode;
} else {
_ = window._;
btoa = window.btoa;
b64encode = function(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
return String.fromCharCode('0x' + p1);
}));
};
}

//prefer native XMLHttpRequest always
/* istanbul ignore if */
if (typeof window !== 'undefined' && typeof window.XMLHttpRequest !== 'undefined'){
Expand Down Expand Up @@ -83,7 +85,7 @@

xhr.setRequestHeader('Content-Type','application/json;charset=UTF-8');
if ((options.token) || (options.username && options.password)) {
var authorization = options.token ? 'token ' + options.token : 'Basic ' + btoa(options.username + ':' + options.password);
var authorization = options.token ? 'token ' + options.token : 'Basic ' + b64encode(options.username + ':' + options.password);
xhr.setRequestHeader('Authorization', authorization);
}
if (data) {
Expand Down Expand Up @@ -417,7 +419,7 @@
};
} else {
content = {
"content": btoa(String.fromCharCode.apply(null, new Uint8Array(content))),
"content": b64encode(String.fromCharCode.apply(null, new Uint8Array(content))),
"encoding": "base64"
};
}
Expand Down Expand Up @@ -675,7 +677,7 @@
if (err && err.error !== 404) return cb(err);
_request("PUT", repoPath + "/contents/" + encodeURI(path), {
message: message,
content: btoa(content),
content: b64encode(content),
branch: branch,
sha: sha
}, cb);
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"description": "A higher-level wrapper around the Github API.",
"main": "github.js",
"dependencies": {
"atob": "^1.1.2",
"btoa": "^1.1.2",
"js-base64": "^2.1.8",
"underscore": "~1.8.3",
"xmlhttprequest": "~1.7.0"
},
Expand Down Expand Up @@ -41,7 +40,8 @@
"url": "https://github.com/michael/github/issues"
},
"browser": {
"xmlhttprequest": false
"xmlhttprequest": false,
"base64": false
},
"testling": {
"files": "test/test.*.js",
Expand Down
14 changes: 14 additions & 0 deletions test/test.repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ test('Create Repo', function(t) {
q.end();
});
});

t.test('repo.writeUnicodeContent', function(q) {
repo.write('master', 'TEST.md', '\u2014', 'Long dash unicode', function(err) {
q.error(err);
repo.read('master', 'TEST.md', function(err, obj) {
q.error(err);
t.equals('\u2014', obj);
});
q.end();
});
});



clearTimeout(timeout);
t.end();
});
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载