Skip to content

Commit

Permalink
Improved uri validation
Browse files Browse the repository at this point in the history
  • Loading branch information
roll committed Dec 29, 2017
1 parent 9574d58 commit 502b26e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/types/string.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const isBase64 = require('validator/lib/isBase64')
const isEmail = require('validator/lib/isEmail')
const isUUID = require('validator/lib/isUUID')
const isURL = require('validator/lib/isURL')
const isString = require('lodash/isString')
const {ERROR} = require('../config')

Expand All @@ -12,7 +13,7 @@ function castString(format, value) {
return ERROR
}
if (format === 'uri') {
if (!_URI_PATTERN.exec(value)) {
if (!isURL(value)) {
return ERROR
}
} else if (format === 'email') {
Expand All @@ -35,7 +36,3 @@ function castString(format, value) {
module.exports = {
castString,
}

// Internal

const _URI_PATTERN = new RegExp('^http[s]?://')
1 change: 1 addition & 0 deletions test/types/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const TESTS = [
['default', '', ''],
['default', 0, ERROR],
['uri', 'http://google.com', 'http://google.com'],
['uri', 'ftp://example.org/resource.txt', 'ftp://example.org/resource.txt'],
['uri', 'string', ERROR],
['uri', '', ERROR],
['uri', 0, ERROR],
Expand Down

0 comments on commit 502b26e

Please sign in to comment.