From 6f4c52a53d10fc7da36ab3abac8a8a502c56205c Mon Sep 17 00:00:00 2001 From: SilverFire - Dmitry Naumenko Date: Sat, 5 Nov 2016 21:07:05 +0200 Subject: [PATCH] Simplified Regex usage in JS Follows 70752b0fc1dde9a32d3565759d77072d3187f4eb --- framework/assets/yii.js | 9 +++------ framework/assets/yii.validation.js | 6 ++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/framework/assets/yii.js b/framework/assets/yii.js index bb69b552f3..e2db617a38 100644 --- a/framework/assets/yii.js +++ b/framework/assets/yii.js @@ -208,8 +208,7 @@ window.yii = (function ($) { var newForm = !$form.length; if (newForm) { - var regexp = /(^\/|:\/\/)/; - if (!action || !regexp.test(action)) { + if (!action || !/(^\/|:\/\/)/.test(action)) { action = window.location.href; } $form = $('
', {method: method, action: action}); @@ -217,13 +216,11 @@ window.yii = (function ($) { if (target) { $form.attr('target', target); } - regexp = /(get|post)/i; - if (!regexp.test(method)) { + if (!/(get|post)/i.test(method)) { $form.append($('', {name: '_method', value: method, type: 'hidden'})); method = 'POST'; } - regexp = /(get|head|options)/i; - if (!regexp.test(method)) { + if (!/(get|head|options)/i.test(method)) { var csrfParam = pub.getCsrfParam(); if (csrfParam) { $form.append($('', {name: csrfParam, value: pub.getCsrfToken(), type: 'hidden'})); diff --git a/framework/assets/yii.validation.js b/framework/assets/yii.validation.js index 3155d1c39a..c49be404db 100644 --- a/framework/assets/yii.validation.js +++ b/framework/assets/yii.validation.js @@ -225,16 +225,14 @@ yii.validation = (function ($) { return; } - var regexp = /:\/\//; - if (options.defaultScheme && !regexp.test(value)) { + if (options.defaultScheme && !/:\/\//.test(value)) { value = options.defaultScheme + '://' + value; } var valid = true; if (options.enableIDN) { - regexp = /^([^:]+):\/\/([^\/]+)(.*)$/; - matches = regexp.exec(value); + var matches = /^([^:]+):\/\/([^\/]+)(.*)$/.exec(value); if (matches === null) { valid = false; } else {