Skip to content

Commit

Permalink
fix: url validator to support http://g.co (#2013)
Browse files Browse the repository at this point in the history
  • Loading branch information
limonte committed Jul 9, 2020
1 parent 4a0ff59 commit 8ab6562
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cypress/integration/methods/input.spec.js
Expand Up @@ -439,6 +439,12 @@ describe('Validation', () => {
})
})

it('default URL validator: http://g.co', (done) => {
defaultInputValidators.url('http://g.co').then(() => {
done()
})
})

it('default URL validator: http://foo.localhost/', (done) => {
defaultInputValidators.url('http://foo.localhost/').then(() => {
done()
Expand Down
4 changes: 2 additions & 2 deletions src/utils/defaultInputValidators.js
Expand Up @@ -5,8 +5,8 @@ export default {
: Promise.resolve(validationMessage || 'Invalid email address')
},
url: (string, validationMessage) => {
// taken from https://stackoverflow.com/a/3809435 with a small change from #1306
return /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)$/.test(string)
// taken from https://stackoverflow.com/a/3809435 with a small change from #1306 and #2013
return /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)$/.test(string)
? Promise.resolve()
: Promise.resolve(validationMessage || 'Invalid URL')
}
Expand Down
6 changes: 5 additions & 1 deletion test/qunit/validation.js
Expand Up @@ -27,12 +27,16 @@ QUnit.test('input.checkValidity()', (assert) => {
})

QUnit.test('default URL validator', (assert) => {
const done = assert.async(3)
const done = assert.async(4)

defaultInputValidators.url('https://google.com').then(() => {
done()
})

defaultInputValidators.url('http://g.co').then(() => {
done()
})

defaultInputValidators.url('http://foo.localhost/').then(() => {
done()
})
Expand Down

0 comments on commit 8ab6562

Please sign in to comment.