Skip to content

Commit

Permalink
feat: checkBucketName in setBucket/initOption/useBucket (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
weiyie authored and PeterRao committed Dec 19, 2019
1 parent 04fb6ba commit 162dfb5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/browser/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ function toArray(obj) {
// };

proto.useBucket = function useBucket(name) {
this._checkBucketName(name);
this.options.bucket = name;
return this;
};

proto.setBucket = function useBucket(name) {
this._checkBucketName(name);
this.options.bucket = name;
return this;
};
Expand Down
1 change: 1 addition & 0 deletions lib/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ proto.listBuckets = async function listBuckets(query, options) {
};

proto.useBucket = function useBucket(name) {
this._checkBucketName(name);
return this.setBucket(name);
};

Expand Down
4 changes: 4 additions & 0 deletions lib/common/client/initOptions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ms = require('humanize-ms');
const urlutil = require('url');
const _checkBucketName = require('../utils/checkBucketName');

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

0 comments on commit 162dfb5

Please sign in to comment.