Skip to content

Commit

Permalink
Additional stuff for #521
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Mar 30, 2016
1 parent 442ba74 commit 9c9220a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#### HEAD

- Added a `isDataURI` validator
([#521](https://github.com/chriso/validator.js/pull/521))
- Fixed a bug with `isURL()` when protocol was missing and :// appeared in the query
([#518](https://github.com/chriso/validator.js/issues/518))

Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ var _isBase = require('./lib/isBase64');

var _isBase2 = _interopRequireDefault(_isBase);

var _isDataURI = require('./lib/isDataURI');

var _isDataURI2 = _interopRequireDefault(_isDataURI);

var _ltrim = require('./lib/ltrim');

var _ltrim2 = _interopRequireDefault(_ltrim);
Expand Down Expand Up @@ -264,7 +268,7 @@ var validator = {
isMobilePhone: _isMobilePhone2.default,
isCurrency: _isCurrency2.default,
isISO8601: _isISO2.default,
isBase64: _isBase2.default,
isBase64: _isBase2.default, isDataURI: _isDataURI2.default,
ltrim: _ltrim2.default, rtrim: _rtrim2.default, trim: _trim2.default,
escape: _escape2.default, unescape: _unescape2.default, stripLow: _stripLow2.default,
whitelist: _whitelist2.default, blacklist: _blacklist2.default,
Expand Down
20 changes: 20 additions & 0 deletions lib/isDataURI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isDataURI;

var _assertString = require('./util/assertString');

var _assertString2 = _interopRequireDefault(_assertString);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var dataURI = /^\s*data:([a-z]+\/[a-z0-9\-\+]+(;[a-z\-]+\=[a-z0-9\-]+)?)?(;base64)?,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i; // eslint-disable-line max-len

function isDataURI(str) {
(0, _assertString2.default)(str);
return dataURI.test(str);
}
module.exports = exports['default'];
9 changes: 8 additions & 1 deletion validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,13 @@
return firstPaddingChar === -1 || firstPaddingChar === len - 1 || firstPaddingChar === len - 2 && str[len - 1] === '=';
}

var dataURI = /^\s*data:([a-z]+\/[a-z0-9\-\+]+(;[a-z\-]+\=[a-z0-9\-]+)?)?(;base64)?,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i; // eslint-disable-line max-len

function isDataURI(str) {
assertString(str);
return dataURI.test(str);
}

function ltrim(str, chars) {
assertString(str);
var pattern = chars ? new RegExp('^[' + chars + ']+', 'g') : /^\s+/g;
Expand Down Expand Up @@ -1071,7 +1078,7 @@
isMobilePhone: isMobilePhone,
isCurrency: isCurrency,
isISO8601: isISO8601,
isBase64: isBase64,
isBase64: isBase64, isDataURI: isDataURI,
ltrim: ltrim, rtrim: rtrim, trim: trim,
escape: escape, unescape: unescape, stripLow: stripLow,
whitelist: whitelist, blacklist: blacklist,
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit 9c9220a

Please sign in to comment.