From 1c4f409aef4930040753ab59b5532b7e430f37cc Mon Sep 17 00:00:00 2001 From: Kieran Brahney Date: Fri, 1 Jul 2022 16:20:23 +0100 Subject: [PATCH 01/32] Build: Updating the master version to 1.19.6-pre. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0bc214db1..2cc35a6bc 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jquery-validation", "title": "jQuery Validation Plugin", "description": "Client-side form validation made easy", - "version": "1.19.5-pre", + "version": "1.19.6-pre", "homepage": "https://jqueryvalidation.org/", "license": "MIT", "author": { From 73c645d7d5f879543c32f03f5231200e3748fc30 Mon Sep 17 00:00:00 2001 From: Kieran Brahney Date: Fri, 1 Jul 2022 16:30:42 +0100 Subject: [PATCH 02/32] Chore: update changelog --- changelog.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 284e5a15c..ca71122fb 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,16 @@ +1.19.5 / 2022-06-01 +=================== + +## Chore + * Add CodeQL analysis [3d3c1fb](https://github.com/jquery-validation/jquery-validation/commit/3d3c1fb880c3c623da334e9b6b32a861a16efeb8) + +## Core + * Fixed jQuery .submit() event shorthand deprecation notice [#2430](https://github.com/jquery-validation/jquery-validation/pull/2430) + * Fixed ReDos vulnerability in url, and url2 validation [5bbd80d](https://github.com/jquery-validation/jquery-validation/commit/5bbd80d27fc6b607d2f7f106c89522051a9fb0dd) + +## Localisation + * Added periods to messages [#2266](https://github.com/jquery-validation/jquery-validation/pull/2266) + 1.19.4 / 2022-05-19 =================== @@ -28,7 +41,7 @@ * Add Accessibility section to Readme (#2149) ## Localization - * Add "pattern" translation for French (#2363) + * Add "pattern" translation for French (#2363) * add phone validate translate for Turkish translation (#2343) 1.19.2 / 2020-05-23 @@ -160,7 +173,7 @@ The hashes for the 1.19.0 release can be found in the file [`jquery-validation-s ## Tests * Pass on the value of the used submit button for scripted submits (#2019) * Use assert#pushResult instead of assert#push (#2018) - + ## All * Fix links after move to organization * Use https From 24f2e277f1cb2c4d0dfcd97ae35997d43136dfbe Mon Sep 17 00:00:00 2001 From: Kieran Date: Fri, 1 Jul 2022 21:39:27 +0100 Subject: [PATCH 03/32] Chore: correct 1.19.5 release date --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index ca71122fb..6bbbd5ccb 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,4 @@ -1.19.5 / 2022-06-01 +1.19.5 / 2022-07-01 =================== ## Chore From 980087a897c1d3a03b87f8d07cf756e8b9bba6d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylvain=20Monn=C3=A9?= Date: Fri, 15 Jul 2022 23:26:56 +0200 Subject: [PATCH 04/32] Core: fix race condition in remote validation rules (#2435) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #2434 Co-authored-by: Sylvain Monné --- src/ajax.js | 17 +++++++++++------ src/core.js | 27 ++++++++++++++++++++++++++- test/methods.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index fb56de4b3..5f87bed20 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -1,5 +1,6 @@ // Ajax mode: abort // usage: $.ajax({ mode: "abort"[, port: "uniqueport"]}); +// $.ajaxAbort( port ); // if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort() var pendingRequests = {}, @@ -10,9 +11,7 @@ if ( $.ajaxPrefilter ) { $.ajaxPrefilter( function( settings, _, xhr ) { var port = settings.port; if ( settings.mode === "abort" ) { - if ( pendingRequests[ port ] ) { - pendingRequests[ port ].abort(); - } + $.ajaxAbort( port ); pendingRequests[ port ] = xhr; } } ); @@ -24,12 +23,18 @@ if ( $.ajaxPrefilter ) { var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode, port = ( "port" in settings ? settings : $.ajaxSettings ).port; if ( mode === "abort" ) { - if ( pendingRequests[ port ] ) { - pendingRequests[ port ].abort(); - } + $.ajaxAbort( port ); pendingRequests[ port ] = ajax.apply( this, arguments ); return pendingRequests[ port ]; } return ajax.apply( this, arguments ); }; } + +// Abort the previous request without sending a new one +$.ajaxAbort = function( port ) { + if ( pendingRequests[ port ] ) { + pendingRequests[ port ].abort(); + delete pendingRequests[ port ]; + } +}; diff --git a/src/core.js b/src/core.js index ddb258119..923b3012b 100644 --- a/src/core.js +++ b/src/core.js @@ -756,6 +756,9 @@ $.extend( $.validator, { val = this.elementValue( element ), result, method, rule, normalizer; + // Abort any pending Ajax request from a previous call to this method. + this.abortRequest( element ); + // Prioritize the local normalizer defined for this element over the global one // if the former exists, otherwise user the global one in case it exists. if ( typeof rules.normalizer === "function" ) { @@ -1095,6 +1098,10 @@ $.extend( $.validator, { return !$.validator.methods.required.call( this, val, element ) && "dependency-mismatch"; }, + elementAjaxPort: function( element ) { + return "validate" + element.name; + }, + startRequest: function( element ) { if ( !this.pending[ element.name ] ) { this.pendingRequest++; @@ -1130,6 +1137,24 @@ $.extend( $.validator, { } }, + abortRequest: function( element ) { + var port; + + if ( this.pending[ element.name ] ) { + port = this.elementAjaxPort( element ); + $.ajaxAbort( port ); + + this.pendingRequest--; + + // Sometimes synchronization fails, make sure pendingRequest is never < 0 + if ( this.pendingRequest < 0 ) { + this.pendingRequest = 0; + } + + delete this.pending[ element.name ]; + } + }, + previousValue: function( element, method ) { method = typeof method === "string" && method || "remote"; @@ -1570,7 +1595,7 @@ $.extend( $.validator, { data[ element.name ] = value; $.ajax( $.extend( true, { mode: "abort", - port: "validate" + element.name, + port: this.elementAjaxPort( element ), dataType: "json", data: data, context: validator.currentForm, diff --git a/test/methods.js b/test/methods.js index fa49939e4..2966ec25f 100644 --- a/test/methods.js +++ b/test/methods.js @@ -801,6 +801,36 @@ QUnit.test( "Fix #697: remote validation uses wrong error messages", function( a } ); } ); +QUnit.test( "Fix #2434: race condition in remote validation rules", function( assert ) { + var e = $( "#username" ), + done1 = assert.async(), + v = $( "#userForm" ).validate( { + rules: { + username: { + required: true, + remote: { + url: "users.php" + } + } + }, + messages: { + username: { + remote: $.validator.format( "{0} in use" ) + } + } + } ); + + e.val( "Peter" ); + v.element( e ); + + e.val( "" ); + v.element( e ); + setTimeout( function() { + assert.equal( v.errorList[ 0 ].message, "This field is required." ); + done1(); + } ); +} ); + QUnit.module( "additional methods" ); QUnit.test( "phone (us)", function( assert ) { From 98fbc5f4287b9e580be6c1404094e9ae31b4abb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylvain=20Monn=C3=A9?= Date: Sun, 17 Jul 2022 13:21:36 +0200 Subject: [PATCH 05/32] Core: remove pending class from fields with an aborted request (#2436) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ref #2434 Ref #2435 Co-authored-by: Sylvain Monné --- src/core.js | 1 + test/methods.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/core.js b/src/core.js index 923b3012b..b7c62c04c 100644 --- a/src/core.js +++ b/src/core.js @@ -1152,6 +1152,7 @@ $.extend( $.validator, { } delete this.pending[ element.name ]; + $( element ).removeClass( this.settings.pendingClass ); } }, diff --git a/test/methods.js b/test/methods.js index 2966ec25f..a65e4b474 100644 --- a/test/methods.js +++ b/test/methods.js @@ -822,11 +822,19 @@ QUnit.test( "Fix #2434: race condition in remote validation rules", function( as e.val( "Peter" ); v.element( e ); + assert.equal( e.hasClass( "error" ), false, "Field 'username' should not have the error class" ); + assert.equal( e.hasClass( "pending" ), true, "field 'username' should have the pending class" ); e.val( "" ); v.element( e ); + assert.equal( v.errorList[ 0 ].message, "This field is required." ); + assert.equal( e.hasClass( "error" ), true, "Field 'username' should have the error class" ); + assert.equal( e.hasClass( "pending" ), false, "field 'username' should not have the pending class" ); + setTimeout( function() { assert.equal( v.errorList[ 0 ].message, "This field is required." ); + assert.equal( e.hasClass( "error" ), true, "Field 'username' should have the error class" ); + assert.equal( e.hasClass( "pending" ), false, "field 'username' should not have the pending class" ); done1(); } ); } ); From f1bb23544bb7a796402b763af115662651aa6dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Monteiro?= Date: Thu, 13 Oct 2022 06:36:37 -0300 Subject: [PATCH 06/32] Localization: Improve required translation in pt_BR (#2445) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "É requerido" although correct is weird in this context (it's much more used in formal settings for documents known as requerimentos) and too much of a literal translation. This change aims to improve user-friendliness in this particular message. --- src/localization/messages_pt_BR.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/localization/messages_pt_BR.js b/src/localization/messages_pt_BR.js index 996c844be..42cd4a6bd 100644 --- a/src/localization/messages_pt_BR.js +++ b/src/localization/messages_pt_BR.js @@ -6,7 +6,7 @@ $.extend( $.validator.messages, { // Core - required: "Este campo é requerido.", + required: "Este campo é obrigatório.", remote: "Por favor, corrija este campo.", email: "Por favor, forneça um endereço de email válido.", url: "Por favor, forneça uma URL válida.", From d46e86c1432f449959025b1c41e4cf16eb62a699 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 11 Nov 2022 11:40:48 +0100 Subject: [PATCH 07/32] Demo: fix minlength validation in ajaxSubmit-integration-demo.html (#2454) --- demo/ajaxSubmit-integration-demo.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/ajaxSubmit-integration-demo.html b/demo/ajaxSubmit-integration-demo.html index 057f18dbe..21a7d38d9 100644 --- a/demo/ajaxSubmit-integration-demo.html +++ b/demo/ajaxSubmit-integration-demo.html @@ -74,7 +74,7 @@

jQuery Validation Plugin

- +

From 29fb609cd093a7b5eca9ed33668b55765a4fc0b0 Mon Sep 17 00:00:00 2001 From: Saurabh <41580629+saurabhsharma2u@users.noreply.github.com> Date: Fri, 11 Nov 2022 21:59:31 +0530 Subject: [PATCH 08/32] Localization: Add Hindi translation (#2453) * Localisation: Update Hindi (India) translation * Hindi Translation for Step Method * HIndi-India Local messages for additional method * file rename as per ISO 639-1 format * removed duplicate message, causing the test fail * removed duplicate "cifES" error message --- src/localization/message_hi.js | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/localization/message_hi.js diff --git a/src/localization/message_hi.js b/src/localization/message_hi.js new file mode 100644 index 000000000..72bf4a149 --- /dev/null +++ b/src/localization/message_hi.js @@ -0,0 +1,42 @@ +/* + * Translated default messages for the jQuery validation plugin. + * Locale: Hindi; हिंदी + */ +$.extend( $.validator.messages, { + required: "आवश्यक फ़ील्ड।", + remote:"इस फ़ील्ड को जांचें।", + email: "एक वैध ई - मेल पते की प्रविष्टि करें।", + url: "कृपया एक वैध वेब पता दर्ज करें।", + date: "कृपया कोई मान्य दिनांक दर्ज करें।", + dateISO: "कृपया एक मान्य दिनांक (ISO) दर्ज करें।", + number: "कृपया सही अंक दर्ज करें।", + digits: "केवल संख्याएं दर्ज करें।", + creditcard: "कृपया एक वैध क्रेडिट कार्ड नंबर डालें।", + equalTo: "मेल नहीं खाता।", + extension: "कृपया एक मान्य एक्सटेंशन वाला मान दर्ज करें।", + maxlength: $.validator.format( "अधिक दर्ज न करें {0} वर्णों में से" ), + minlength: $.validator.format( "कृपया कम से कम {0} वर्ण दर्ज करें।" ), + rangelength: $.validator.format( "कृपया {0} और {1} वर्णों के बीच एक मान दर्ज करें।" ), + range: $.validator.format( "कृपया {0} और {1} के बीच एक मान दर्ज करें।" ), + max: $.validator.format( "कृपया {0} से कम या उसके बराबर मान दर्ज करें।" ), + min: $.validator.format( "कृपया {0} से अधिक या उसके बराबर मान दर्ज करें।" ), + nieES: "कृपया एक मान्य NIE दर्ज करें।", + cifES: "कृपया एक मान्य CIF दर्ज करें.", + currency: "कृपया एक मान्य मुद्रा दर्ज करें।.", + step: $.validator.format( "{0} का गुणज होना चाहिए।" ), + abaRoutingNumber:"कृपया एक मान्य रूटिंग नंबर दर्ज करें।", + accept:"कृपया एक मान्य माइमटाइप वाला मान दर्ज करें।", + alphanumeric:"कृपया, केवल अक्षर, संख्याएं और अंडरस्कोर।", + bankaccountNL:"कृपया एक वैध बैंक खाता संख्या निर्दिष्ट करें।", + bankorgiroaccountNL:"कृपया एक वैध बैंक या जीरो खाता संख्या निर्दिष्ट करें।", + bic:"कृपया कोई मान्य BIC कोड निर्दिष्ट करें।", + ziprange:"आपका ज़िप कोड 902xx-xxxx से 905xx-xxxx की सीमा में होना चाहिए।", + zipcodeUS:"निर्दिष्ट यूएस ज़िप कोड अमान्य है।", + vinUS:"निर्दिष्ट वाहन पहचान संख्या (VIN) अमान्य है।", + time12h:"कृपया 12 घंटे पूर्वाह्न/अपराह्न प्रारूप में मान्य समय दर्ज करें।", + time:"कृपया 00:00 और 23:59 के बीच एक वैध समय दर्ज करें।", + strippedminlength:"कृपया कम से कम {0} वर्ण दर्ज करें।", + stateUS:"कृपया एक वैध प्रदेश निर्दिष्ट करें।", + skip_or_fill_minimum:"कृपया या तो इन फ़ील्ड को छोड़ दें या उनमें से कम से कम {0} भरें।", + require_from_group:"कृपया इनमें से कम से कम {0} को भरें।" +} ); From 13b859e35735086cb320423b3585d8a6edee4349 Mon Sep 17 00:00:00 2001 From: Warren White <111083379+wewhite@users.noreply.github.com> Date: Thu, 1 Dec 2022 02:50:24 -0800 Subject: [PATCH 09/32] Additional: vinUS validation fails on valid vin numbers (#2460) * Removed === compare, changed to == Compare by value and type (===) does not work for this algorithm, as both cd and cdv can be either types at the same time. By comparing by value only (==) cd and cdv can be either integer or string, as a string number will be converted to a number reqardless of type. * Rewrote forloop, removed nested forloop * Additional: fixed spacing issues * Additional: Add vinUS.js validation test cases Test cases include default test with 17 one's, and additional US and Canada VIN * Additional: add two more test casses for vinUS * Additional: removed text license number, should be VIN --- src/additional/vinUS.js | 69 ++++++++++++++++++---------------------- test/additional/vinUS.js | 11 +++++++ test/index.html | 1 + 3 files changed, 43 insertions(+), 38 deletions(-) create mode 100644 test/additional/vinUS.js diff --git a/src/additional/vinUS.js b/src/additional/vinUS.js index 15460d725..3fd2d128b 100644 --- a/src/additional/vinUS.js +++ b/src/additional/vinUS.js @@ -11,44 +11,37 @@ * @cat Plugins/Validate/Methods */ $.validator.addMethod( "vinUS", function( v ) { - if ( v.length !== 17 ) { - return false; - } + if ( v.length !== 17 ) { + return false; + } - var LL = [ "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ], - VL = [ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 7, 9, 2, 3, 4, 5, 6, 7, 8, 9 ], - FL = [ 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2 ], - rs = 0, - i, n, d, f, cd, cdv; + var LL = [ "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ], + VL = [ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 7, 9, 2, 3, 4, 5, 6, 7, 8, 9 ], + FL = [ 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2 ], + rs = 0, + i, n, d, f, cd, cdv; - for ( i = 0; i < 17; i++ ) { - f = FL[ i ]; - d = v.slice( i, i + 1 ); - if ( i === 8 ) { - cdv = d; - } - if ( !isNaN( d ) ) { - d *= f; - } else { - for ( n = 0; n < LL.length; n++ ) { - if ( d.toUpperCase() === LL[ n ] ) { - d = VL[ n ]; - d *= f; - if ( isNaN( cdv ) && n === 8 ) { - cdv = LL[ n ]; - } - break; - } - } - } - rs += d; - } - cd = rs % 11; - if ( cd === 10 ) { - cd = "X"; - } - if ( cd === cdv ) { - return true; - } - return false; + for ( i = 0; i < 17; i++ ) { + f = FL[ i ]; + d = v.slice( i, i + 1 ); + if ( isNaN( d ) ) { + d = d.toUpperCase(); + n = VL[ LL.indexOf( d ) ]; + } else { + n = parseInt( d, 10 ); + } + if ( i === 8 ) + { + cdv = n; + if ( d === "X" ) { + cdv = 10; + } + } + rs += n * f; + } + cd = rs % 11; + if ( cd === cdv ) { + return true; + } + return false; }, "The specified vehicle identification number (VIN) is invalid." ); diff --git a/test/additional/vinUS.js b/test/additional/vinUS.js new file mode 100644 index 000000000..3311b0111 --- /dev/null +++ b/test/additional/vinUS.js @@ -0,0 +1,11 @@ +QUnit.test( "vinUS", function( assert ) { + var method = methodTest( "vinUS" ); + assert.ok( method( "11111111111111111" ), "Valid test VIN number" ); + assert.ok( method( "1FTFX1CT9CFD06231" ), "Valid US VIN number" ); + assert.ok( method( "2FTHF26F8SCA68695" ), "Valid CAN VIN number" ); + assert.ok( method( "LJCPCBLCX11000237" ), "Valid VIN with X check digit" ); + assert.ok( !method( "LJCPCBLC011000237" ), "Invalid VIN with 0 check digit" ); + assert.ok( !method( "2FTHF26F8" ), "InValid VIN number" ); + assert.ok( !method( "11111111X1111111" ), "Invalid test VIN" ); + assert.ok( !method( "1111111101111111" ), "Invalid test VIN" ); +} ); diff --git a/test/index.html b/test/index.html index bf22a640a..17c6438b8 100644 --- a/test/index.html +++ b/test/index.html @@ -19,6 +19,7 @@ + From cfe74a19b671b0983b3b13dbf959619cfe926de9 Mon Sep 17 00:00:00 2001 From: Leonardo Spina Date: Tue, 24 Jan 2023 11:37:07 +0000 Subject: [PATCH 10/32] Core: Call to resetInternals removed in remote validation callback (#2242) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Core: Call to resetInternals removed in remote validation callback * Core: Add unit test for issue #2150 fix * Core: fix code style errors Co-authored-by: leonardospina Co-authored-by: Julien Tschäppät --- src/core.js | 1 - test/index.html | 4 ++++ test/test.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index b7c62c04c..5a2fb1ce4 100644 --- a/src/core.js +++ b/src/core.js @@ -1607,7 +1607,6 @@ $.extend( $.validator, { validator.settings.messages[ element.name ][ method ] = previous.originalMessage; if ( valid ) { submitted = validator.formSubmitted; - validator.resetInternals(); validator.toHide = validator.errorsFor( element ); validator.formSubmitted = submitted; validator.successList.push( element ); diff --git a/test/index.html b/test/index.html index 17c6438b8..f27ad1d76 100644 --- a/test/index.html +++ b/test/index.html @@ -72,6 +72,10 @@

+
+
+ +
diff --git a/test/test.js b/test/test.js index 298df0dbc..02462c933 100644 --- a/test/test.js +++ b/test/test.js @@ -2060,6 +2060,37 @@ QUnit.test( "[Remote rule] #1508: Validation fails to trigger when next field is check( "abc" ); } ); +$.mockjax( { + url: "issue2150TestForm.action", + response: function() { + this.responseText = "true"; + }, + responseTime: 1 +} ); + +QUnit.test( "Remote validation should not reset existing errors (#2150)", function( assert ) { + assert.expect( 3 ); + var done = assert.async(); + $( "#issue2150TestForm" ).validate( { + rules: { + remoteTestedInput: { + remote: "issue2150TestForm.action" + }, + requiredInput: "required" + } + } ); + + assert.equal( $( "#requiredInput" ).attr( "class" ), undefined, "#requiredInput should not have any class" ); + + var isValid = $( "#issue2150TestForm" ).valid(); + + setTimeout( function() { + assert.equal( $( "#requiredInput" ).attr( "class" ), "error", "#requiredInput should have \"error\" class" ); + assert.equal( isValid, false, "Form should have error" ); + done(); + } ); +} ); + QUnit.test( "validate checkbox on click", function( assert ) { function errors( expected, message ) { assert.equal( v.size(), expected, message ); From 7a490d8f39bd988027568ddcf51755e1f4688902 Mon Sep 17 00:00:00 2001 From: Volkan Ceylan Date: Wed, 1 Feb 2023 13:26:18 +0300 Subject: [PATCH 11/32] Core: Added escapeHtml option to avoid XSS attacks via showLabel methods (#2462) --- src/core.js | 15 ++++++++--- test/error-placement.js | 57 +++++++++++++++++++++++++++++++++++++++++ test/index.html | 6 +++++ 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/src/core.js b/src/core.js index 5a2fb1ce4..ab891487b 100644 --- a/src/core.js +++ b/src/core.js @@ -945,14 +945,23 @@ $.extend( $.validator, { error.removeClass( this.settings.validClass ).addClass( this.settings.errorClass ); // Replace message on existing label - error.html( message ); + if ( this.settings && this.settings.escapeHtml ) { + error.text( message || "" ); + } else { + error.html( message || "" ); + } } else { // Create error element error = $( "<" + this.settings.errorElement + ">" ) .attr( "id", elementID + "-error" ) - .addClass( this.settings.errorClass ) - .html( message || "" ); + .addClass( this.settings.errorClass ); + + if ( this.settings && this.settings.escapeHtml ) { + error.text( message || "" ); + } else { + error.html( message || "" ); + } // Maintain reference to the element to be placed into the DOM place = error; diff --git a/test/error-placement.js b/test/error-placement.js index 7c00ce0cd..05e5c565f 100644 --- a/test/error-placement.js +++ b/test/error-placement.js @@ -440,3 +440,60 @@ QUnit.test( "#1632: Error hidden, but input error class not removed", function( assert.equal( v.numberOfInvalids(), 0, "There is no error" ); assert.equal( box2.hasClass( "error" ), false, "Box2 should not have an error class" ); } ); + +QUnit.test( "test settings.escapeHtml undefined", function( assert ) { + var form = $( "#escapeHtmlForm1" ), + field = $( "#escapeHtmlForm1text" ); + + form.validate( { + messages: { + escapeHtmlForm1text: { + required: "" + } + } + } ); + + assert.ok( !field.valid() ); + assert.hasError( field, "required" ); + + var label = form.find( "label" ); + assert.equal( label.length, 1 ); + assert.equal( label.html(), "" ); + + label.html( "" ); + assert.ok( !field.valid() ); + assert.equal( label.html(), "" ); + + field.val( "foo" ); + assert.ok( field.valid() ); + assert.noErrorFor( field ); +} ); + +QUnit.test( "test settings.escapeHtml true", function( assert ) { + var form = $( "#escapeHtmlForm2" ), + field = $( "#escapeHtmlForm2text" ); + + form.validate( { + escapeHtml: true, + messages: { + escapeHtmlForm2text: { + required: "" + } + } + } ); + + assert.ok( !field.valid() ); + assert.hasError( field, "required" ); + + var label = form.find( "label" ); + assert.equal( label.length, 1 ); + assert.equal( label.html(), "<script>console.log('!!!');</script>" ); + + label.html( "" ); + assert.ok( !field.valid() ); + assert.equal( label.html(), "<script>console.log('!!!');</script>" ); + + field.val( "foo" ); + assert.ok( field.valid() ); + assert.noErrorFor( field ); +} ); diff --git a/test/index.html b/test/index.html index f27ad1d76..601f6a505 100644 --- a/test/index.html +++ b/test/index.html @@ -467,6 +467,12 @@

+
+ +
+
+ +
From 716cdc92d11ed38525f99f47e07023e10ee6f4b4 Mon Sep 17 00:00:00 2001 From: Kieran Date: Wed, 14 Jun 2023 23:48:02 +0100 Subject: [PATCH 12/32] Update 01_bug_report.md --- .github/ISSUE_TEMPLATE/01_bug_report.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/01_bug_report.md b/.github/ISSUE_TEMPLATE/01_bug_report.md index 856a1af54..9087c0176 100644 --- a/.github/ISSUE_TEMPLATE/01_bug_report.md +++ b/.github/ISSUE_TEMPLATE/01_bug_report.md @@ -1,7 +1,7 @@ --- name: Bug report about: Report something that's broken. Please ensure that you're using the latest version. -labels: Bug +labels: ["Bug", "Status: Unverified"] --- From 935280706c0cf390ff47f5e2efdea9566de860c2 Mon Sep 17 00:00:00 2001 From: Kieran Date: Wed, 14 Jun 2023 23:49:59 +0100 Subject: [PATCH 13/32] Update stale.yml --- .github/workflows/stale.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index eebce5aeb..3e3c347e7 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -22,10 +22,7 @@ jobs: with: repo-token: ${{ secrets.GITHUB_TOKEN }} stale-issue-message: > - This issue/proposal has been automatically marked as idle and stale because it hasn't - had any recent activity. It will be automatically closed if no further activity - occurs. If you think this is wrong, or the problem still persists, just pop - a reply in the comments and one of the maintainers will (try!) to follow up. + This issue lacks verification. Please provide a reproduction link. Thank you for contributing :) stale-pr-message: > @@ -38,5 +35,5 @@ jobs: stale-issue-label: 'stale' stale-pr-label: 'stale' exempt-all-milestones: true - exempt-issue-labels: 'bug, help wanted' + exempt-issue-labels: 'Status: Verified' exempt-pr-labels: 'MERGE ME, NEEDS REVIEW' From fa8d211a3e336af3256962fda99841ed1cb125ef Mon Sep 17 00:00:00 2001 From: Kieran Date: Thu, 17 Aug 2023 12:36:48 +0100 Subject: [PATCH 14/32] Update 01_bug_report.md --- .github/ISSUE_TEMPLATE/01_bug_report.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/01_bug_report.md b/.github/ISSUE_TEMPLATE/01_bug_report.md index 9087c0176..e0a6968ea 100644 --- a/.github/ISSUE_TEMPLATE/01_bug_report.md +++ b/.github/ISSUE_TEMPLATE/01_bug_report.md @@ -1,7 +1,7 @@ --- name: Bug report about: Report something that's broken. Please ensure that you're using the latest version. -labels: ["Bug", "Status: Unverified"] +labels: ["Type: Bug", "Status: Unverified"] --- From 3cdcde80e49622bda27d18c84797ed5215aea764 Mon Sep 17 00:00:00 2001 From: Kieran Date: Thu, 17 Aug 2023 12:37:23 +0100 Subject: [PATCH 15/32] Update 02_feature_request.md --- .github/ISSUE_TEMPLATE/02_feature_request.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/02_feature_request.md b/.github/ISSUE_TEMPLATE/02_feature_request.md index 6d49cfb86..03feaaf61 100644 --- a/.github/ISSUE_TEMPLATE/02_feature_request.md +++ b/.github/ISSUE_TEMPLATE/02_feature_request.md @@ -1,7 +1,7 @@ --- name: Feature request about: Wouldn't it be nice if jquery-validate could ... -labels: Feature +labels: ["Type: Feature"] --- From bb5ec97ac32de4265fb794527efcb5693adba267 Mon Sep 17 00:00:00 2001 From: EricDunsworth <1907279+EricDunsworth@users.noreply.github.com> Date: Thu, 17 Aug 2023 10:48:44 -0400 Subject: [PATCH 16/32] Localization: Add French currency translation (#2471) --- src/localization/messages_fr.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/localization/messages_fr.js b/src/localization/messages_fr.js index 97192b971..dc23300ad 100644 --- a/src/localization/messages_fr.js +++ b/src/localization/messages_fr.js @@ -41,6 +41,7 @@ $.extend( $.validator.messages, { email2: "Veuillez fournir une adresse électronique valide.", url2: "Veuillez fournir une adresse URL valide.", creditcardtypes: "Veuillez fournir un numéro de carte de crédit valide.", + currency: "Veuillez fournir une monnaie valide.", ipv4: "Veuillez fournir une adresse IP v4 valide.", ipv6: "Veuillez fournir une adresse IP v6 valide.", require_from_group: $.validator.format( "Veuillez fournir au moins {0} de ces champs." ), From 7ba6372c04705a8b90101deec1b0561f12a02518 Mon Sep 17 00:00:00 2001 From: EricDunsworth <1907279+EricDunsworth@users.noreply.github.com> Date: Fri, 25 Aug 2023 05:27:11 -0400 Subject: [PATCH 17/32] Localization: Rename message_hi.js to messages_hindi.js (#2470) This makes it consistent with other i18n file names (which are all written in plural). --- src/localization/{message_hi.js => messages_hi.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/localization/{message_hi.js => messages_hi.js} (100%) diff --git a/src/localization/message_hi.js b/src/localization/messages_hi.js similarity index 100% rename from src/localization/message_hi.js rename to src/localization/messages_hi.js From 2ecb6be81a0b2bb06434d1b5077ff3dcec5ea354 Mon Sep 17 00:00:00 2001 From: bytestream Date: Mon, 9 Oct 2023 23:47:29 +0100 Subject: [PATCH 18/32] Update version 1.20.0-pre --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2cc35a6bc..9f2d81a0c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jquery-validation", "title": "jQuery Validation Plugin", "description": "Client-side form validation made easy", - "version": "1.19.6-pre", + "version": "1.20.0-pre", "homepage": "https://jqueryvalidation.org/", "license": "MIT", "author": { From 99772f23f28d3e752f30c95ab0e2c6c22bce4441 Mon Sep 17 00:00:00 2001 From: bytestream Date: Mon, 9 Oct 2023 23:56:40 +0100 Subject: [PATCH 19/32] Update generateArtifacts command in build/release.js --- build/release.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/release.js b/build/release.js index 504658cf1..a71ffeeda 100644 --- a/build/release.js +++ b/build/release.js @@ -38,7 +38,7 @@ Release.define({ }, generateArtifacts: function( done ) { - Release.exec( "grunt release", "Grunt command failed" ); + Release.exec( "npx grunt release", "Grunt command failed" ); // Keep this list of files in sync with package.json's files key done([ "dist/localization/", From a354e8ac2546e859acc5cec5391a8767df306313 Mon Sep 17 00:00:00 2001 From: bytestream Date: Tue, 10 Oct 2023 00:15:15 +0100 Subject: [PATCH 20/32] Build: Updating the master version to 1.20.1-pre. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9f2d81a0c..f1a027aa7 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jquery-validation", "title": "jQuery Validation Plugin", "description": "Client-side form validation made easy", - "version": "1.20.0-pre", + "version": "1.20.1-pre", "homepage": "https://jqueryvalidation.org/", "license": "MIT", "author": { From 672a3601d71efa7b8089c365447b1999e521c5fb Mon Sep 17 00:00:00 2001 From: bytestream Date: Tue, 10 Oct 2023 00:27:38 +0100 Subject: [PATCH 21/32] Chore: update changelog.md --- changelog.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/changelog.md b/changelog.md index 6bbbd5ccb..4680381ae 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,23 @@ +1.20.0 / 2023-10-10 +=================== + +## Additional + * Fixed vinUS validation failing on valid vin numbers [#2460](https://github.com/jquery-validation/jquery-validation/pull/2460) + +## Core + * Fixed race condition in remote validation rules [#2435](https://github.com/jquery-validation/jquery-validation/pull/2435) + * Removed pending class from fields with an aborted request [#2436](https://github.com/jquery-validation/jquery-validation/pull/2436) + * Fixed remote validation error tracking [#2242](https://github.com/jquery-validation/jquery-validation/pull/2242) + * Added escapeHtml option to avoid XSS attacks via showLabel method [#2462](https://github.com/jquery-validation/jquery-validation/pull/2462) + +## Demo + * Fixed minlength validation in ajaxSubmit-integration-demo.html [#2454](https://github.com/jquery-validation/jquery-validation/pull/2454) + +## Localisation + * Improved required translation in pt_BR [#2445](https://github.com/jquery-validation/jquery-validation/pull/2445) + * Added Hindi translation [#2453](https://github.com/jquery-validation/jquery-validation/pull/2453) + * Added French currency translation [#2471](https://github.com/jquery-validation/jquery-validation/pull/2471) + 1.19.5 / 2022-07-01 =================== From 0c811ce17c075bbfb14c6fc8daf02e383eae1ef4 Mon Sep 17 00:00:00 2001 From: Mohamed Baddi Date: Wed, 20 Mar 2024 13:06:54 +0000 Subject: [PATCH 22/32] Localization: Update Arabic translations (#2485) * feat: update arabic messages translations * psr: coding style * wip: coding style --- src/localization/messages_ar.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/localization/messages_ar.js b/src/localization/messages_ar.js index dad165e58..d6e1433b1 100644 --- a/src/localization/messages_ar.js +++ b/src/localization/messages_ar.js @@ -19,5 +19,34 @@ $.extend( $.validator.messages, { rangelength: $.validator.format( "عدد الحروف يجب أن يكون بين {0} و {1}" ), range: $.validator.format( "رجاء إدخال عدد قيمته بين {0} و {1}" ), max: $.validator.format( "رجاء إدخال عدد أقل من أو يساوي {0}" ), - min: $.validator.format( "رجاء إدخال عدد أكبر من أو يساوي {0}" ) + min: $.validator.format( "رجاء إدخال عدد أكبر من أو يساوي {0}" ), + step: $.validator.format( "يرجى تقديم قيمة من مضاعفات {0}" ), + maxWords: $.validator.format( "يرجى تقديم ما لا يزيد عن {0} كلمات" ), + minWords: $.validator.format( "يرجى تقديم {0} كلمات على الأقل" ), + rangeWords: $.validator.format( "يرجى تقديم ما بين {0} و{1} كلمة" ), + letterswithbasicpunc: "يرجى تقديم الحروف وعلامات الترقيم فقط", + alphanumeric: "يرجى تقديم الحروف والأرقام والمسافات والتسطير فقط", + lettersonly: "يرجى تقديم الحروف فقط", + nowhitespace: "من فضلك لا تدخل المساحات البيضاء", + ziprange: "يرجى تقديم الرمز البريدي بين 902xx-xxxx و905-xx-xxxx", + integer: "يرجى تقديم رقم غير عشري موجب أو سالب", + vinUS: "يرجى تقديم رقم تعريف المركبة (VIN)", + dateITA: "يرجى تقديم تاريخ صالح", + time: "يرجى تقديم وقت صالح بين 00:00 و23:59", + phoneUS: "الرجاء تقديم رقم هاتف صالح", + phoneUK: "الرجاء تقديم رقم هاتف صالح", + mobileUK: "يرجى تقديم رقم هاتف محمول صالح", + strippedminlength: $.validator.format( "يرجى تقديم {0} حرفًا على الأقل" ), + email2: "يرجى تقديم عنوان بريد إلكتروني صالح", + url2: "يرجى إدخال عنوان بريد إلكتروني صحيح", + creditcardtypes: "يرجى تقديم رقم بطاقة ائتمان صالح", + currency: "يرجى تقديم عملة صالحة", + ipv4: "يرجى تقديم عنوان IP v4 صالح", + ipv6: "يرجى تقديم عنوان IP v6 صالح", + require_from_group: $.validator.format( "يرجى تقديم ما لا يقل عن {0} من هذه الحقول" ), + nifES: "يرجى تقديم رقم TIN صالح", + nieES: "يرجى تقديم رقم NIE صالح", + cifES: "يرجى تقديم رقم CIF صالح", + postalCodeCA: "يرجى تقديم رمز بريدي صالح", + pattern: "التنسيق غير صالح" } ); From 569e62234c321f4da30015f516f09c367c09a804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylvain=20Monn=C3=A9?= Date: Sun, 21 Apr 2024 10:59:31 +0200 Subject: [PATCH 23/32] Core: fix remote validation when input is the same as in aborted request (#2481) Fixes #2479 --- src/core.js | 3 ++- test/methods.js | 38 +++++++++++++++++++++++++++++++++++++- test/test.js | 10 ++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/core.js b/src/core.js index ab891487b..426b2551a 100644 --- a/src/core.js +++ b/src/core.js @@ -1594,11 +1594,12 @@ $.extend( $.validator, { param = typeof param === "string" && { url: param } || param; optionDataString = $.param( $.extend( { data: value }, param.data ) ); - if ( previous.old === optionDataString ) { + if ( previous.valid !== null && previous.old === optionDataString ) { return previous.valid; } previous.old = optionDataString; + previous.valid = null; validator = this; this.startRequest( element ); data = {}; diff --git a/test/methods.js b/test/methods.js index a65e4b474..b2644f59d 100644 --- a/test/methods.js +++ b/test/methods.js @@ -623,7 +623,7 @@ QUnit.test( "remote, data previous querystring", function( assert ) { rules: { lastname: { remote: { - url: "users.php", + url: "users3.php", type: "POST", data: { firstname: function() { @@ -839,6 +839,42 @@ QUnit.test( "Fix #2434: race condition in remote validation rules", function( as } ); } ); +QUnit.test( "Fix #2479: Remote validation fails when input is the same as in aborted request", function( assert ) { + var e = $( "#username" ), + done1 = assert.async(), + v = $( "#userForm" ).validate( { + rules: { + username: { + remote: { + url: "users.php" + } + } + }, + messages: { + username: { + remote: $.validator.format( "{0} in use" ) + } + } + } ); + + e.val( "Peter" ); + v.element( e ); + assert.equal( e.hasClass( "error" ), false, "Field 'username' should not have the error class" ); + assert.equal( e.hasClass( "pending" ), true, "field 'username' should have the pending class" ); + + e.val( "Peter" ); + v.element( e ); + assert.equal( e.hasClass( "error" ), false, "Field 'username' should not have the error class" ); + assert.equal( e.hasClass( "pending" ), true, "field 'username' should have the pending class" ); + + setTimeout( function() { + assert.equal( v.errorList[ 0 ].message, "Peter in use" ); + assert.equal( e.hasClass( "error" ), true, "Field 'username' should have the error class" ); + assert.equal( e.hasClass( "pending" ), false, "field 'username' should not have the pending class" ); + done1(); + } ); +} ); + QUnit.module( "additional methods" ); QUnit.test( "phone (us)", function( assert ) { diff --git a/test/test.js b/test/test.js index 02462c933..c6f123f69 100644 --- a/test/test.js +++ b/test/test.js @@ -31,6 +31,16 @@ $.mockjax( { responseTime: 1 } ); +$.mockjax( { + url: "users3.php", + data: { + lastname: "last-name" + }, + responseText: "false", + responseStatus: 200, + responseTime: 1 +} ); + $.mockjax( { url: "echo.php", response: function( data ) { From 21951645948cebea491e6b1882b41576fe44e333 Mon Sep 17 00:00:00 2001 From: Kieran Brahney Date: Thu, 13 Jun 2024 14:28:14 +0100 Subject: [PATCH 24/32] Build: Updating the master version to 1.20.2-pre. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f1a027aa7..dfe9a5322 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jquery-validation", "title": "jQuery Validation Plugin", "description": "Client-side form validation made easy", - "version": "1.20.1-pre", + "version": "1.20.2-pre", "homepage": "https://jqueryvalidation.org/", "license": "MIT", "author": { From 0f8400fc55c801b4201ce41290b2aae21e2b20ec Mon Sep 17 00:00:00 2001 From: Kieran Brahney Date: Thu, 13 Jun 2024 14:37:54 +0100 Subject: [PATCH 25/32] Chore: update changelog --- changelog.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/changelog.md b/changelog.md index 4680381ae..65b392ff8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,12 @@ +1.20.1 / 2024-06-13 +=================== + +## Core + * Fix remote validation when input is the same as in aborted request [#2481](https://github.com/jquery-validation/jquery-validation/pull/2481) + +## Localisation + * Update Arabic translations [#2485](https://github.com/jquery-validation/jquery-validation/pull/2485) + 1.20.0 / 2023-10-10 =================== From 75f51237e422360e53c5c23ad8da307223fe0b8a Mon Sep 17 00:00:00 2001 From: Daniel Hobi Date: Fri, 28 Jun 2024 17:10:19 +0200 Subject: [PATCH 26/32] Core: Add support for Web Components (#2493) Co-authored-by: Daniel Hobi --- .jscsrc | 5 ++++- .jshintignore | 1 + Gruntfile.js | 12 +++++++++++- package.json | 2 +- src/core.js | 20 +++++++++++--------- test/custom-elements.js | 17 +++++++++++++++++ test/index.html | 4 ++++ test/test.js | 21 +++++++++++++++++++++ 8 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 test/custom-elements.js diff --git a/.jscsrc b/.jscsrc index d50b36c38..018d8ca09 100644 --- a/.jscsrc +++ b/.jscsrc @@ -1,5 +1,8 @@ { "preset": "jquery", "maximumLineLength": null, - "requireCamelCaseOrUpperCaseIdentifiers": null + "requireCamelCaseOrUpperCaseIdentifiers": null, + "excludeFiles": [ + "test/custom-elements.js" + ] } diff --git a/.jshintignore b/.jshintignore index ffdbea7be..420537ee7 100644 --- a/.jshintignore +++ b/.jshintignore @@ -4,3 +4,4 @@ test/qunit/ dist/ demo/ *.min.js +test/custom-elements.js diff --git a/Gruntfile.js b/Gruntfile.js index 18cd73e33..2f4e3ea6c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -115,7 +115,17 @@ grunt.initConfig( { } }, qunit: { - files: "test/index.html" + files: "test/index.html", + options: { + puppeteer: { + args: [ + "--headless", + "--disable-web-security", + "--allow-file-access-from-files" + ] + }, + timeout: 10000 + } }, jshint: { options: { diff --git a/package.json b/package.json index dfe9a5322..26c433102 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "grunt-contrib-concat": "1.0.1", "grunt-contrib-copy": "1.0.0", "grunt-contrib-jshint": "1.0.0", - "grunt-contrib-qunit": "1.2.0", + "grunt-contrib-qunit": "10.0.0", "grunt-contrib-uglify": "1.0.1", "grunt-contrib-watch": "1.0.0", "grunt-jscs": "2.8.0", diff --git a/src/core.js b/src/core.js index 426b2551a..1b8bf875f 100644 --- a/src/core.js +++ b/src/core.js @@ -275,6 +275,7 @@ $.extend( $.validator, { onsubmit: true, ignore: ":hidden", ignoreTitle: false, + customElements: [], onfocusin: function( element ) { this.lastActive = element; @@ -422,17 +423,17 @@ $.extend( $.validator, { settings[ eventType ].call( validator, this, event ); } } - + var focusListeners = [ ":text", "[type='password']", "[type='file']", "select", "textarea", "[type='number']", "[type='search']", + "[type='tel']", "[type='url']", "[type='email']", "[type='datetime']", "[type='date']", "[type='month']", + "[type='week']", "[type='time']", "[type='datetime-local']", "[type='range']", "[type='color']", + "[type='radio']", "[type='checkbox']", "[contenteditable]", "[type='button']" ]; + var clickListeners = [ "select", "option", "[type='radio']", "[type='checkbox']" ]; $( this.currentForm ) - .on( "focusin.validate focusout.validate keyup.validate", - ":text, [type='password'], [type='file'], select, textarea, [type='number'], [type='search'], " + - "[type='tel'], [type='url'], [type='email'], [type='datetime'], [type='date'], [type='month'], " + - "[type='week'], [type='time'], [type='datetime-local'], [type='range'], [type='color'], " + - "[type='radio'], [type='checkbox'], [contenteditable], [type='button']", delegate ) + .on( "focusin.validate focusout.validate keyup.validate", focusListeners.concat( this.settings.customElements ).join( ", " ), delegate ) // Support: Chrome, oldIE // "select" is provided as event.target when clicking a option - .on( "click.validate", "select, option, [type='radio'], [type='checkbox']", delegate ); + .on( "click.validate", clickListeners.concat( this.settings.customElements ).join( ", " ), delegate ); if ( this.settings.invalidHandler ) { $( this.currentForm ).on( "invalid-form.validate", this.settings.invalidHandler ); @@ -629,11 +630,12 @@ $.extend( $.validator, { elements: function() { var validator = this, - rulesCache = {}; + rulesCache = {}, + selectors = [ "input", "select", "textarea", "[contenteditable]" ]; // Select all valid inputs inside the form (no submit or reset buttons) return $( this.currentForm ) - .find( "input, select, textarea, [contenteditable]" ) + .find( selectors.concat( this.settings.customElements ).join( ", " ) ) .not( ":submit, :reset, :image, :disabled" ) .not( this.settings.ignore ) .filter( function() { diff --git a/test/custom-elements.js b/test/custom-elements.js new file mode 100644 index 000000000..7a4afc327 --- /dev/null +++ b/test/custom-elements.js @@ -0,0 +1,17 @@ +class CustomTextElement extends HTMLElement { + static formAssociated = true; + static observedAttributes = ["name", "id"]; + + constructor() { + super(); + this.internals_ = this.attachInternals(); + } + get form() { + return this.internals_ != null ? this.internals_.form : null; + } + get name() { + return this.getAttribute("name"); + } +} + +window.customElements.define("custom-text", CustomTextElement); diff --git a/test/index.html b/test/index.html index 601f6a505..e23e52dfc 100644 --- a/test/index.html +++ b/test/index.html @@ -11,6 +11,7 @@ + @@ -472,6 +473,9 @@

+
+
+ diff --git a/test/test.js b/test/test.js index c6f123f69..f9fbd4bdc 100644 --- a/test/test.js +++ b/test/test.js @@ -2786,3 +2786,24 @@ QUnit.test( "stopRequest() should submit the form once pendingRequests === 0", f // Submit the form $( button ).click(); } ); + +QUnit.test( "Assign rules to customElement via .validate() method", function( assert ) { + var form = $( "#customElementsForm" ); + var v = form.validate( { + customElements: [ "custom-text" ], + rules: { + customTextElement: { + required: true + } + } + } ); + var customTextElementRules = $( "#customTextElement", form ).rules(); + var expectedRules = { required: true }; + + assert.deepEqual( + customTextElementRules, expectedRules, "The rules should be the same" + ); + + v.form(); + assert.equal( v.numberOfInvalids(), 1, "The form has one error" ); +} ); From e837cc49beec2b17f7e18eaa3e1e9676e14c3133 Mon Sep 17 00:00:00 2001 From: Christopher Stieg Date: Sat, 29 Jun 2024 06:11:15 -0400 Subject: [PATCH 27/32] Core: Allow negative decimal with no 0 (#2483) * Core: Allow negative decimal with no 0 * Update regex --------- Co-authored-by: METALCOMPINC\cstieg Co-authored-by: Kieran --- src/core.js | 2 +- test/methods.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index 1b8bf875f..240e2737b 100644 --- a/src/core.js +++ b/src/core.js @@ -1485,7 +1485,7 @@ $.extend( $.validator, { // https://jqueryvalidation.org/number-method/ number: function( value, element ) { - return this.optional( element ) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test( value ); + return this.optional( element ) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:-?\.\d+)?$/.test( value ); }, // https://jqueryvalidation.org/digits-method/ diff --git a/test/methods.js b/test/methods.js index b2644f59d..e0d02eef2 100644 --- a/test/methods.js +++ b/test/methods.js @@ -177,6 +177,7 @@ QUnit.test( "number", function( assert ) { assert.ok( method( "123,000.00" ), "Valid decimal" ); assert.ok( method( "-123,000.00" ), "Valid decimal" ); assert.ok( method( ".100" ), "Valid decimal" ); + assert.ok( method( "-.100" ), "Valid decimal" ); assert.ok( !method( "1230,000.00" ), "Invalid decimal" ); assert.ok( !method( "123.0.0,0" ), "Invalid decimal" ); assert.ok( !method( "x123" ), "Invalid decimal" ); From 09f67cbf770d2b83982859950565b4b5eb377389 Mon Sep 17 00:00:00 2001 From: Kieran Date: Wed, 17 Jul 2024 10:18:39 +0100 Subject: [PATCH 28/32] Update package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 26c433102..e4ee566df 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jquery-validation", "title": "jQuery Validation Plugin", "description": "Client-side form validation made easy", - "version": "1.20.2-pre", + "version": "1.21.0-pre", "homepage": "https://jqueryvalidation.org/", "license": "MIT", "author": { From bd54405de2c0c820d7903f625a54b157e707f75e Mon Sep 17 00:00:00 2001 From: Kieran Brahney Date: Wed, 17 Jul 2024 10:45:25 +0100 Subject: [PATCH 29/32] Build: Updating the master version to 1.21.1-pre. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e4ee566df..7fd85ca91 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jquery-validation", "title": "jQuery Validation Plugin", "description": "Client-side form validation made easy", - "version": "1.21.0-pre", + "version": "1.21.1-pre", "homepage": "https://jqueryvalidation.org/", "license": "MIT", "author": { From 6cd68f68e395b1c3a2588e6e7d64f561410c2dc0 Mon Sep 17 00:00:00 2001 From: Kieran Date: Mon, 16 Dec 2024 19:10:59 +0000 Subject: [PATCH 30/32] Update stale.yml --- .github/workflows/stale.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 3e3c347e7..6332ce773 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -35,5 +35,5 @@ jobs: stale-issue-label: 'stale' stale-pr-label: 'stale' exempt-all-milestones: true - exempt-issue-labels: 'Status: Verified' + exempt-issue-labels: 'Status: Verified, Type: Feature' exempt-pr-labels: 'MERGE ME, NEEDS REVIEW' From 07d2594c8201863ea03d901551fb0f17cf11b3c7 Mon Sep 17 00:00:00 2001 From: Kieran Date: Thu, 12 Jun 2025 11:20:12 +0100 Subject: [PATCH 31/32] Chore: downgrade ubuntu (#2518) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb9551a9c..7b3883f6f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ on: jobs: linux_tests: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 From 707623a5cede70bdce8a911c2925f7786911e97d Mon Sep 17 00:00:00 2001 From: appel <61596+appel@users.noreply.github.com> Date: Thu, 12 Jun 2025 06:22:47 -0400 Subject: [PATCH 32/32] Localization: Additional string translations for messages_nl.js (#2517) * Update messages_nl.js Additional string translations (on par with DE). * Fixes styling issue. Added missing spaces inside the parentheses of $.validator.format() calls. --- src/localization/messages_nl.js | 42 ++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/localization/messages_nl.js b/src/localization/messages_nl.js index 2d6a6970e..abee59f9e 100644 --- a/src/localization/messages_nl.js +++ b/src/localization/messages_nl.js @@ -30,5 +30,45 @@ $.extend( $.validator.messages, { postalcodeNL: "Vul hier een geldige postcode in.", bankaccountNL: "Vul hier een geldig bankrekeningnummer in.", giroaccountNL: "Vul hier een geldig gironummer in.", - bankorgiroaccountNL: "Vul hier een geldig bank- of gironummer in." + bankorgiroaccountNL: "Vul hier een geldig bank- of gironummer in.", + + maxWords: $.validator.format( "Vul hier maximaal {0} woorden in." ), + minWords: $.validator.format( "Vul hier minimaal {0} woorden in." ), + rangeWords: $.validator.format( "Vul hier tussen {0} en {1} woorden in." ), + accept: "Vul hier een waarde in met een geldig MIME-type.", + alphanumeric: "Vul hier alleen letters, cijfers of underscores in.", + bic: "Vul hier een geldige BIC-code in.", + creditcardtypes: "Vul hier een geldig creditcardnummer in.", + currency: "Vul hier een geldige valuta in.", + integer: "Vul hier een geheel getal in.", + ipv4: "Vul hier een geldig IPv4-adres in.", + ipv6: "Vul hier een geldig IPv6-adres in.", + lettersonly: "Vul hier alleen letters in.", + letterswithbasicpunc: "Vul hier alleen letters of leestekens in.", + netmask: "Vul hier een geldig netmasker in.", + notEqualTo: "Vul hier een andere waarde in. De waarden mogen niet gelijk zijn.", + nowhitespace: "Spaties zijn niet toegestaan.", + pattern: "Ongeldig formaat.", + require_from_group: $.validator.format( "Vul minimaal {0} van deze velden in." ), + skip_or_fill_minimum: $.validator.format( "Sla deze velden over of vul er minimaal {0} van in." ), + strippedminlength: $.validator.format( "Vul hier minimaal {0} tekens in." ), + time: "Vul hier een geldige tijd in tussen 00:00 en 23:59.", + time12h: "Vul hier een geldige tijd in (12-uursnotatie).", + cifES: "Vul hier een geldig CIF-nummer in.", + cpfBR: "Vul hier een geldig CPF-nummer in.", + mobileUK: "Vul hier een geldig Brits mobiel nummer in.", + nieES: "Vul hier een geldig NIE-nummer in.", + nifES: "Vul hier een geldig NIF-nummer in.", + nipPL: "Vul hier een geldig NIP-nummer in.", + phonesUK: "Vul hier een geldig Brits telefoonnummer in.", + phoneUK: "Vul hier een geldig Brits telefoonnummer in.", + phoneUS: "Vul hier een geldig Amerikaans telefoonnummer in.", + postalcodeBR: "Vul hier een geldige Braziliaanse postcode in.", + postalCodeCA: "Vul hier een geldige Canadese postcode in.", + postalcodeIT: "Vul hier een geldige Italiaanse postcode in.", + postcodeUK: "Vul hier een geldige Britse postcode in.", + stateUS: "Vul hier een geldige Amerikaanse staat in.", + vinUS: "Het opgegeven voertuigidentificatienummer (VIN) is ongeldig.", + zipcodeUS: "De opgegeven Amerikaanse postcode is ongeldig.", + ziprange: "Uw postcode moet binnen het bereik 902xx-xxxx tot 905xx-xxxx liggen." } );