From 8295bd580b12a3b040ced4897b605f8d70404854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=AC=BC=E5=8C=85=E4=B8=8D=E6=98=AF=E5=8C=85?= <425486057@qq.com> Date: Tue, 21 May 2019 15:53:48 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20video=20path=20accept=20chinese=20or=20?= =?UTF-8?q?other=20language=20.=20issue#28=20=E3=80=90=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E3=80=91=E8=A7=86=E9=A2=91=E8=B7=AF=E5=BE=84=E6=9C=89=E4=B8=AD?= =?UTF-8?q?=E6=96=87=E6=97=A0=E6=B3=95=E9=80=9A=E8=BF=87=E6=AD=A3=E5=88=99?= =?UTF-8?q?=E6=A3=80=E9=AA=8C=20issue#28?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + lib/AudioUploader.js | 5 +++-- lib/VideoUploader.js | 5 +++-- lib/utils.js | 15 ++++++++++++++- src/AudioUploader.js | 3 +-- src/VideoUploader.js | 3 +-- src/utils.js | 12 ++++++++++++ 7 files changed, 35 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 00cbbdf5..ada11378 100644 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,4 @@ typings/ # dotenv environment variables file .env +.idea/ \ No newline at end of file diff --git a/lib/AudioUploader.js b/lib/AudioUploader.js index 8db1dbe8..39d09644 100644 --- a/lib/AudioUploader.js +++ b/lib/AudioUploader.js @@ -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); } @@ -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 = @@ -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('链接已存在'); diff --git a/lib/VideoUploader.js b/lib/VideoUploader.js index b9d2a89e..6a3654be 100644 --- a/lib/VideoUploader.js +++ b/lib/VideoUploader.js @@ -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); } @@ -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 = @@ -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('链接已存在'); diff --git a/lib/utils.js b/lib/utils.js index f6c406c4..bfa0fb7c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", { }); exports.extractImageSource = extractImageSource; exports.replaceImageSource = replaceImageSource; +exports.linkRegx = void 0; function extractImageSource(html) { var imgReg = /|\/>)/gi; @@ -25,4 +26,16 @@ function replaceImageSource(html, origin, target) { return html.replace(//ig, function (img, src) { return src === origin ? img.replace(src, target) : img; }); -} \ No newline at end of file +} + +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; \ No newline at end of file diff --git a/src/AudioUploader.js b/src/AudioUploader.js index c8dfd686..0041809b 100644 --- a/src/AudioUploader.js +++ b/src/AudioUploader.js @@ -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: { @@ -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 { diff --git a/src/VideoUploader.js b/src/VideoUploader.js index 8f088fff..048290e0 100644 --- a/src/VideoUploader.js +++ b/src/VideoUploader.js @@ -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: { @@ -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 { diff --git a/src/utils.js b/src/utils.js index 342c3ef8..4032c873 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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')