Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ typings/
# dotenv environment variables file
.env

.idea/
5 changes: 3 additions & 2 deletions lib/AudioUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var _Tag = _interopRequireDefault(require("./Tag"));

var _Upload = _interopRequireDefault(require("./Upload"));

var _utils = require("./utils");

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

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
Expand Down Expand Up @@ -76,7 +78,6 @@ var style = {
color: '#f04134'
}
};
var linkRegx = /^https?:\/\/(([a-zA-Z0-9_-])+(\.)?)*(:\d+)?(\/((\.)?(\?)?=?&?[a-zA-Z0-9,_-](\?)?)*)*$/i;
var timeoutInstance = null;

var UploadModal =
Expand Down Expand Up @@ -127,7 +128,7 @@ function (_React$PureComponent) {

if (currentSource === '') {
_this.showErrorMsg('链接不能为空');
} else if (!linkRegx.test(currentSource)) {
} else if (!_utils.linkRegx.test(currentSource)) {
_this.showErrorMsg('非法的链接');
} else if (sources.indexOf(currentSource) !== -1) {
_this.showErrorMsg('链接已存在');
Expand Down
5 changes: 3 additions & 2 deletions lib/VideoUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var _Tag = _interopRequireDefault(require("./Tag"));

var _Upload = _interopRequireDefault(require("./Upload"));

var _utils = require("./utils");

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

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
Expand Down Expand Up @@ -76,7 +78,6 @@ var style = {
color: '#f04134'
}
};
var linkRegx = /^https?:\/\/(([a-zA-Z0-9_-])+(\.)?)*(:\d+)?(\/((\.)?(\?)?=?&?[a-zA-Z0-9,_-](\?)?)*)*$/i;
var timeoutInstance = null;

var UploadModal =
Expand Down Expand Up @@ -127,7 +128,7 @@ function (_React$PureComponent) {

if (currentSource === '') {
_this.showErrorMsg('链接不能为空');
} else if (!linkRegx.test(currentSource)) {
} else if (!_utils.linkRegx.test(currentSource)) {
_this.showErrorMsg('非法的链接');
} else if (sources.indexOf(currentSource) !== -1) {
_this.showErrorMsg('链接已存在');
Expand Down
15 changes: 14 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
});
exports.extractImageSource = extractImageSource;
exports.replaceImageSource = replaceImageSource;
exports.linkRegx = void 0;

function extractImageSource(html) {
var imgReg = /<img.*?(?:>|\/>)/gi;
Expand All @@ -25,4 +26,16 @@ function replaceImageSource(html, origin, target) {
return html.replace(/<img.*?src="(.*?)".*?\/?>/ig, function (img, src) {
return src === origin ? img.replace(src, target) : img;
});
}
}

var linkRegString = '^((https|http|ftp|rtsp|mms)?://)' + '?(([0-9a-zA-Z_!~*\'().&=+$%-]+: )?[0-9a-zA-Z_!~*\'().&=+$%-]+@)?' + // ftp的user@
'(([0-9]{1,3}.){3}[0-9]{1,3}' + // IP形式的URL- 199.194.52.184
'|' + // 允许IP和DOMAIN(域名)
'([0-9a-zA-Z_!~*\'()-]+.)*' + // 域名- www.
'([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z].' + // 二级域名
'[a-zA-Z]{2,6})' + // first level domain- .com or .museum
'(:[0-9]{1,4})?' + // port - :80
'((/?)|' + // a slash isn't required if there is no file name
'(/[0-9a-zA-Z_!~*\'().;?:@&=+$,%#-]+)+/?)$';
var linkRegx = new RegExp(linkRegString, 'i');
exports.linkRegx = linkRegx;
3 changes: 1 addition & 2 deletions src/AudioUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React from 'react'
import Select from './Select'
import Tag from './Tag'
import Upload from './Upload'
import {linkRegx} from './utils'

const style = {
paramsConfig: {
Expand Down Expand Up @@ -40,8 +41,6 @@ const style = {
},
}

const linkRegx = /^https?:\/\/(([a-zA-Z0-9_-])+(\.)?)*(:\d+)?(\/((\.)?(\?)?=?&?[a-zA-Z0-9,_-](\?)?)*)*$/i

let timeoutInstance = null

class UploadModal extends React.PureComponent {
Expand Down
3 changes: 1 addition & 2 deletions src/VideoUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React from 'react'
import Select from './Select'
import Tag from './Tag'
import Upload from './Upload'
import {linkRegx} from './utils'

const style = {
paramsConfig: {
Expand Down Expand Up @@ -40,8 +41,6 @@ const style = {
},
}

const linkRegx = /^https?:\/\/(([a-zA-Z0-9_-])+(\.)?)*(:\d+)?(\/((\.)?(\?)?=?&?[a-zA-Z0-9,_-](\?)?)*)*$/i

let timeoutInstance = null

class UploadModal extends React.PureComponent {
Expand Down
12 changes: 12 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,15 @@ export function replaceImageSource(html, origin, target) {
return src === origin ? img.replace(src, target) : img
})
}

const linkRegString = '^((https|http|ftp|rtsp|mms)?://)' +
'?(([0-9a-zA-Z_!~*\'().&=+$%-]+: )?[0-9a-zA-Z_!~*\'().&=+$%-]+@)?' + // ftp的user@
'(([0-9]{1,3}.){3}[0-9]{1,3}' + // IP形式的URL- 199.194.52.184
'|' + // 允许IP和DOMAIN(域名)
'([0-9a-zA-Z_!~*\'()-]+.)*' + // 域名- www.
'([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z].' + // 二级域名
'[a-zA-Z]{2,6})' + // first level domain- .com or .museum
'(:[0-9]{1,4})?' + // port - :80
'((/?)|' + // a slash isn't required if there is no file name
'(/[0-9a-zA-Z_!~*\'().;?:@&=+$,%#-]+)+/?)$'
export const linkRegx = new RegExp(linkRegString, 'i')