Skip to content

Commit

Permalink
Merge 8ebead3 into a0d9567
Browse files Browse the repository at this point in the history
  • Loading branch information
noyobo committed Nov 20, 2015
2 parents a0d9567 + 8ebead3 commit ed657d7
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
8 changes: 5 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "async-validator",
"version": "1.3.4",
"version": "1.3.5",
"description": "validate form asynchronous",
"keywords": [
"validator",
Expand All @@ -13,7 +13,9 @@
"type": "git",
"url": "git@github.com:yiminghe/async-validator.git"
},
"files":["lib"],
"files": [
"lib"
],
"main": "./lib/index",
"bugs": {
"url": "http://github.com/yiminghe/async-validator/issues"
Expand Down Expand Up @@ -42,4 +44,4 @@
"pre-commit": [
"lint"
]
}
}
2 changes: 1 addition & 1 deletion src/rule/type.js
Expand Up @@ -2,7 +2,7 @@ import util from '../util';
import required from './required';
const pattern = {
email: /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/,
url: /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/,
url: /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})(([\/\w\.-]*)?)(\?[-_+=~\.;&%\w]*)?(\#[-_\/\!\w]*)?( *)?$/i,
hex: /^#?([a-f0-9]{6}|[a-f0-9]{3})$/i,
};

Expand Down
67 changes: 67 additions & 0 deletions tests/index.spec.js
Expand Up @@ -288,5 +288,72 @@ describe('async-validator', function () {
done();
})
});

it('works for type url has query', function (done) {
new Schema({
v: {
type: 'url'
}
}).validate({
v: 'http://www.taobao.com/abc?a=a'
}, function (errors) {
expect(errors).to.be(null);
done();
})
});

it('works for type url has hash', function (done) {
new Schema({
v: {
type: 'url'
}
}).validate({
v: 'http://www.taobao.com/abc#!abc'
}, function (errors) {
expect(errors).to.be(null);
done();
})
});

it('works for type url has query and has', function (done) {
new Schema({
v: {
type: 'url'
}
}).validate({
v: 'http://www.taobao.com/abc?abc=%23&b=a~c#abc'
}, function (errors) {
expect(errors).to.be(null);
done();
})
});

it('works for type url has query and has space', function (done) {
new Schema({
v: {
type: 'url'
}
}).validate({
v: 'http://www.taobao.com/abc?abc=%23&b=a~c#abc '
}, function (errors) {
expect(errors).to.be(null);
done();
})
});


it('works for type not a valid url', function (done) {
new Schema({
v: {
type: 'url'
}
}).validate({
v: 'http://www.taobao.com/abc?abc=%23&b= a~c#abc '
}, function (errors) {
expect(errors.length).to.be(1);
expect(errors[0].message).to.be('v is not a valid url')
done();
})
});
});
});

0 comments on commit ed657d7

Please sign in to comment.