Skip to content

Commit 162dfb5

Browse files
weiyiePeterRao
authored andcommitted
feat: checkBucketName in setBucket/initOption/useBucket (#709)
1 parent 04fb6ba commit 162dfb5

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

lib/browser/bucket.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ function toArray(obj) {
6262
// };
6363

6464
proto.useBucket = function useBucket(name) {
65+
this._checkBucketName(name);
6566
this.options.bucket = name;
6667
return this;
6768
};
6869

6970
proto.setBucket = function useBucket(name) {
71+
this._checkBucketName(name);
7072
this.options.bucket = name;
7173
return this;
7274
};

lib/bucket.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ proto.listBuckets = async function listBuckets(query, options) {
7373
};
7474

7575
proto.useBucket = function useBucket(name) {
76+
this._checkBucketName(name);
7677
return this.setBucket(name);
7778
};
7879

lib/common/client/initOptions.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const ms = require('humanize-ms');
22
const urlutil = require('url');
3+
const _checkBucketName = require('../utils/checkBucketName');
34

45
function setEndpoint(endpoint, secure) {
56
let url = urlutil.parse(endpoint);
@@ -34,6 +35,9 @@ module.exports = function (options) {
3435
|| !options.accessKeySecret) {
3536
throw new Error('require accessKeyId, accessKeySecret');
3637
}
38+
if (!_checkBucketName(options.bucket)) {
39+
throw new Error('The bucket must be conform to the specifications');
40+
}
3741
const opts = Object.assign({
3842
region: 'oss-cn-hangzhou',
3943
internal: false,

0 commit comments

Comments
 (0)