Skip to content

Commit 367521b

Browse files
binghaiwangPeterRao
authored andcommitted
fix: userAgent with alpha and beta (#373)
1 parent 0c682d9 commit 367521b

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

lib/browser/client.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,12 @@ proto._getUserAgent = function _getUserAgent() {
424424
plat = 'Node.js ' + process.version.slice(1) + ' on ' + process.platform + ' ' + process.arch;
425425
}
426426

427-
return sdk + ' ' + plat;
427+
return this._checkUserAgent(sdk + ' ' + plat);
428+
};
429+
430+
proto._checkUserAgent = function _checkUserAgent(ua) {
431+
var userAgent = ua.replace(/\u03b1/, "alpha").replace(/\u03b2/, "beta");
432+
return userAgent;
428433
};
429434

430435
/*

lib/client.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,12 @@ proto._getUserAgent = function _getUserAgent() {
409409
plat = 'Node.js ' + process.version.slice(1) + ' on ' + process.platform + ' ' + process.arch;
410410
}
411411

412-
return sdk + ' ' + plat;
412+
return this._checkUserAgent(sdk + ' ' + plat);
413+
};
414+
415+
proto._checkUserAgent = function _checkUserAgent(ua) {
416+
var userAgent = ua.replace(/\u03b1/, "alpha").replace(/\u03b2/, "beta");
417+
return userAgent;
413418
};
414419

415420
/*

test/browser.tests.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ describe('browser', function () {
307307
'aliyun-sdk-js/' + pkg.version + ' ' + platform.description));
308308
});
309309

310+
it('should check beta or alpha User-Agent', function () {
311+
var store = oss(ossConfig);
312+
var ua_beta = store._checkUserAgent('aliyun-sdk-nodejs/4.12.2 Node.js β-8.4.0 on darwin x64');
313+
assert.equal(ua_beta, 'aliyun-sdk-nodejs/4.12.2 Node.js beta-8.4.0 on darwin x64');
314+
var ua_alpha = store._checkUserAgent('aliyun-sdk-nodejs/4.12.2 Node.js α-8.4.0 on darwin x64');
315+
assert.equal(ua_alpha, 'aliyun-sdk-nodejs/4.12.2 Node.js alpha-8.4.0 on darwin x64');
316+
});
317+
310318

311319
it('should trim access id/key', function () {
312320
var store = oss({

test/client.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,14 @@ describe('test/client.test.js', function () {
287287
'aliyun-sdk-nodejs/' + pkg.version + ' Node.js ' + process.version.slice(1)));
288288
});
289289

290+
it('should check beta or alpha User-Agent', function () {
291+
var store = oss(config);
292+
var ua_beta = store._checkUserAgent('aliyun-sdk-nodejs/4.12.2 Node.js β-8.4.0 on darwin x64');
293+
assert.equal(ua_beta, 'aliyun-sdk-nodejs/4.12.2 Node.js beta-8.4.0 on darwin x64');
294+
var ua_alpha = store._checkUserAgent('aliyun-sdk-nodejs/4.12.2 Node.js α-8.4.0 on darwin x64');
295+
assert.equal(ua_alpha, 'aliyun-sdk-nodejs/4.12.2 Node.js alpha-8.4.0 on darwin x64');
296+
});
297+
290298
it('should check browser and version', function* () {
291299
var store = oss(config);
292300
assert(store.checkBrowserAndVersion("", ""));

0 commit comments

Comments
 (0)