Skip to content

Commit 13d056a

Browse files
authored
[Infrastructure] Update jquery-validation periodically (#56725)
Adds a Github action to update jquery-validation automatically to a newer version on a monthly basis.
1 parent 79f745d commit 13d056a

File tree

31 files changed

+885
-190
lines changed

31 files changed

+885
-190
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Update jquery-validation
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 1 * *' # Run on the first day of the month
6+
workflow_dispatch: # Allow manual runs
7+
8+
permissions:
9+
contents: write
10+
issues: write
11+
pull-requests: write
12+
13+
jobs:
14+
update-jquery-validate:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v2
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '20.x'
25+
26+
- name: Set RepoRoot
27+
run: echo "RepoRoot=$(pwd)" >> $GITHUB_ENV
28+
29+
- name: Update dependencies
30+
working-directory: ${{ env.RepoRoot }}/src/Mvc/build
31+
run: |
32+
npm install --no-lockfile
33+
npm run build
34+
npm run update-identity-ui-scripts
35+
echo "JQUERY_VALIDATE_VERSION=$(npm ls jquery-validation --json | jq -r '.dependencies["jquery-validation"].version')" >> $GITHUB_ENV
36+
37+
- name: Update script tags
38+
working-directory: ${{ env.RepoRoot }}/src/Identity/UI
39+
run: node update-jquery-validate.mjs
40+
41+
- name: Create Pull Request
42+
uses: dotnet/actions-create-pull-request@v4
43+
with:
44+
token: ${{ secrets.GITHUB_TOKEN }}
45+
commit-message: Update jquery.validate to ${{ env.JQUERY_VALIDATE_VERSION }}
46+
title: '[Templates][Identity] Update jquery-validation to ${{ env.JQUERY_VALIDATE_VERSION }}'
47+
body: |
48+
Updates the jquery-validation scripts to ${{ env.JQUERY_VALIDATE_VERSION }}
49+
branch: update-jquery-validate-to-${{ env.JQUERY_VALIDATE_VERSION }}
50+
paths: |
51+
**/jquery.validate.js
52+
**/jquery.validate.min.js
53+
**/*.cshtml
54+
src/Identity/UI/jquery-validate-versions.json
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"currentVersion": "1.20.0",
3+
"integrity": "sha256-ic6hxNWCB3IBDsXq0z5KpKHmcJc1anmnh0xGOi0C5Dw="
4+
}

src/Identity/UI/src/Areas/Identity/Pages/V4/_ValidationScriptsPartial.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<script src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
44
</environment>
55
<environment exclude="Development">
6-
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.5/jquery.validate.min.js"
6+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.20.0/jquery.validate.min.js"
77
asp-fallback-src="~/Identity/lib/jquery-validation/dist/jquery.validate.min.js"
88
asp-fallback-test="window.jQuery && window.jQuery.validator"
99
crossorigin="anonymous"
10-
integrity="sha256-JwUksNJ6/R07ZiLRoXbGeNrtlFZMFDKX4hemPiHOmCA=">
10+
integrity="sha256-ic6hxNWCB3IBDsXq0z5KpKHmcJc1anmnh0xGOi0C5Dw=">
1111
</script>
1212
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/4.0.0/jquery.validate.unobtrusive.min.js"
1313
asp-fallback-src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"

src/Identity/UI/src/Areas/Identity/Pages/V5/_ValidationScriptsPartial.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<script src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
44
</environment>
55
<environment exclude="Development">
6-
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.5/jquery.validate.min.js"
6+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.20.0/jquery.validate.min.js"
77
asp-fallback-src="~/Identity/lib/jquery-validation/dist/jquery.validate.min.js"
88
asp-fallback-test="window.jQuery && window.jQuery.validator"
99
crossorigin="anonymous"
10-
integrity="sha256-JwUksNJ6/R07ZiLRoXbGeNrtlFZMFDKX4hemPiHOmCA=">
10+
integrity="sha256-ic6hxNWCB3IBDsXq0z5KpKHmcJc1anmnh0xGOi0C5Dw=">
1111
</script>
1212
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/4.0.0/jquery.validate.unobtrusive.min.js"
1313
asp-fallback-src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"

src/Identity/UI/src/assets/V4/lib/jquery-validation/dist/jquery.validate.js

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*!
2-
* jQuery Validation Plugin v1.19.5
2+
* jQuery Validation Plugin v1.20.0
33
*
44
* https://jqueryvalidation.org/
55
*
6-
* Copyright (c) 2022 Jörn Zaefferer
6+
* Copyright (c) 2023 Jörn Zaefferer
77
* Released under the MIT license
88
*/
99
(function( factory ) {
@@ -774,6 +774,9 @@ $.extend( $.validator, {
774774
val = this.elementValue( element ),
775775
result, method, rule, normalizer;
776776

777+
// Abort any pending Ajax request from a previous call to this method.
778+
this.abortRequest( element );
779+
777780
// Prioritize the local normalizer defined for this element over the global one
778781
// if the former exists, otherwise user the global one in case it exists.
779782
if ( typeof rules.normalizer === "function" ) {
@@ -960,14 +963,23 @@ $.extend( $.validator, {
960963
error.removeClass( this.settings.validClass ).addClass( this.settings.errorClass );
961964

962965
// Replace message on existing label
963-
error.html( message );
966+
if ( this.settings && this.settings.escapeHtml ) {
967+
error.text( message || "" );
968+
} else {
969+
error.html( message || "" );
970+
}
964971
} else {
965972

966973
// Create error element
967974
error = $( "<" + this.settings.errorElement + ">" )
968975
.attr( "id", elementID + "-error" )
969-
.addClass( this.settings.errorClass )
970-
.html( message || "" );
976+
.addClass( this.settings.errorClass );
977+
978+
if ( this.settings && this.settings.escapeHtml ) {
979+
error.text( message || "" );
980+
} else {
981+
error.html( message || "" );
982+
}
971983

972984
// Maintain reference to the element to be placed into the DOM
973985
place = error;
@@ -1113,6 +1125,10 @@ $.extend( $.validator, {
11131125
return !$.validator.methods.required.call( this, val, element ) && "dependency-mismatch";
11141126
},
11151127

1128+
elementAjaxPort: function( element ) {
1129+
return "validate" + element.name;
1130+
},
1131+
11161132
startRequest: function( element ) {
11171133
if ( !this.pending[ element.name ] ) {
11181134
this.pendingRequest++;
@@ -1148,6 +1164,25 @@ $.extend( $.validator, {
11481164
}
11491165
},
11501166

1167+
abortRequest: function( element ) {
1168+
var port;
1169+
1170+
if ( this.pending[ element.name ] ) {
1171+
port = this.elementAjaxPort( element );
1172+
$.ajaxAbort( port );
1173+
1174+
this.pendingRequest--;
1175+
1176+
// Sometimes synchronization fails, make sure pendingRequest is never < 0
1177+
if ( this.pendingRequest < 0 ) {
1178+
this.pendingRequest = 0;
1179+
}
1180+
1181+
delete this.pending[ element.name ];
1182+
$( element ).removeClass( this.settings.pendingClass );
1183+
}
1184+
},
1185+
11511186
previousValue: function( element, method ) {
11521187
method = typeof method === "string" && method || "remote";
11531188

@@ -1588,7 +1623,7 @@ $.extend( $.validator, {
15881623
data[ element.name ] = value;
15891624
$.ajax( $.extend( true, {
15901625
mode: "abort",
1591-
port: "validate" + element.name,
1626+
port: this.elementAjaxPort( element ),
15921627
dataType: "json",
15931628
data: data,
15941629
context: validator.currentForm,
@@ -1599,7 +1634,6 @@ $.extend( $.validator, {
15991634
validator.settings.messages[ element.name ][ method ] = previous.originalMessage;
16001635
if ( valid ) {
16011636
submitted = validator.formSubmitted;
1602-
validator.resetInternals();
16031637
validator.toHide = validator.errorsFor( element );
16041638
validator.formSubmitted = submitted;
16051639
validator.successList.push( element );
@@ -1624,6 +1658,7 @@ $.extend( $.validator, {
16241658

16251659
// Ajax mode: abort
16261660
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
1661+
// $.ajaxAbort( port );
16271662
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()
16281663

16291664
var pendingRequests = {},
@@ -1634,9 +1669,7 @@ if ( $.ajaxPrefilter ) {
16341669
$.ajaxPrefilter( function( settings, _, xhr ) {
16351670
var port = settings.port;
16361671
if ( settings.mode === "abort" ) {
1637-
if ( pendingRequests[ port ] ) {
1638-
pendingRequests[ port ].abort();
1639-
}
1672+
$.ajaxAbort( port );
16401673
pendingRequests[ port ] = xhr;
16411674
}
16421675
} );
@@ -1648,14 +1681,20 @@ if ( $.ajaxPrefilter ) {
16481681
var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
16491682
port = ( "port" in settings ? settings : $.ajaxSettings ).port;
16501683
if ( mode === "abort" ) {
1651-
if ( pendingRequests[ port ] ) {
1652-
pendingRequests[ port ].abort();
1653-
}
1684+
$.ajaxAbort( port );
16541685
pendingRequests[ port ] = ajax.apply( this, arguments );
16551686
return pendingRequests[ port ];
16561687
}
16571688
return ajax.apply( this, arguments );
16581689
};
16591690
}
1691+
1692+
// Abort the previous request without sending a new one
1693+
$.ajaxAbort = function( port ) {
1694+
if ( pendingRequests[ port ] ) {
1695+
pendingRequests[ port ].abort();
1696+
delete pendingRequests[ port ];
1697+
}
1698+
};
16601699
return $;
16611700
}));

src/Identity/UI/src/assets/V4/lib/jquery-validation/dist/jquery.validate.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Identity/UI/src/assets/V5/lib/jquery-validation/dist/jquery.validate.js

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*!
2-
* jQuery Validation Plugin v1.19.5
2+
* jQuery Validation Plugin v1.20.0
33
*
44
* https://jqueryvalidation.org/
55
*
6-
* Copyright (c) 2022 Jörn Zaefferer
6+
* Copyright (c) 2023 Jörn Zaefferer
77
* Released under the MIT license
88
*/
99
(function( factory ) {
@@ -774,6 +774,9 @@ $.extend( $.validator, {
774774
val = this.elementValue( element ),
775775
result, method, rule, normalizer;
776776

777+
// Abort any pending Ajax request from a previous call to this method.
778+
this.abortRequest( element );
779+
777780
// Prioritize the local normalizer defined for this element over the global one
778781
// if the former exists, otherwise user the global one in case it exists.
779782
if ( typeof rules.normalizer === "function" ) {
@@ -960,14 +963,23 @@ $.extend( $.validator, {
960963
error.removeClass( this.settings.validClass ).addClass( this.settings.errorClass );
961964

962965
// Replace message on existing label
963-
error.html( message );
966+
if ( this.settings && this.settings.escapeHtml ) {
967+
error.text( message || "" );
968+
} else {
969+
error.html( message || "" );
970+
}
964971
} else {
965972

966973
// Create error element
967974
error = $( "<" + this.settings.errorElement + ">" )
968975
.attr( "id", elementID + "-error" )
969-
.addClass( this.settings.errorClass )
970-
.html( message || "" );
976+
.addClass( this.settings.errorClass );
977+
978+
if ( this.settings && this.settings.escapeHtml ) {
979+
error.text( message || "" );
980+
} else {
981+
error.html( message || "" );
982+
}
971983

972984
// Maintain reference to the element to be placed into the DOM
973985
place = error;
@@ -1113,6 +1125,10 @@ $.extend( $.validator, {
11131125
return !$.validator.methods.required.call( this, val, element ) && "dependency-mismatch";
11141126
},
11151127

1128+
elementAjaxPort: function( element ) {
1129+
return "validate" + element.name;
1130+
},
1131+
11161132
startRequest: function( element ) {
11171133
if ( !this.pending[ element.name ] ) {
11181134
this.pendingRequest++;
@@ -1148,6 +1164,25 @@ $.extend( $.validator, {
11481164
}
11491165
},
11501166

1167+
abortRequest: function( element ) {
1168+
var port;
1169+
1170+
if ( this.pending[ element.name ] ) {
1171+
port = this.elementAjaxPort( element );
1172+
$.ajaxAbort( port );
1173+
1174+
this.pendingRequest--;
1175+
1176+
// Sometimes synchronization fails, make sure pendingRequest is never < 0
1177+
if ( this.pendingRequest < 0 ) {
1178+
this.pendingRequest = 0;
1179+
}
1180+
1181+
delete this.pending[ element.name ];
1182+
$( element ).removeClass( this.settings.pendingClass );
1183+
}
1184+
},
1185+
11511186
previousValue: function( element, method ) {
11521187
method = typeof method === "string" && method || "remote";
11531188

@@ -1588,7 +1623,7 @@ $.extend( $.validator, {
15881623
data[ element.name ] = value;
15891624
$.ajax( $.extend( true, {
15901625
mode: "abort",
1591-
port: "validate" + element.name,
1626+
port: this.elementAjaxPort( element ),
15921627
dataType: "json",
15931628
data: data,
15941629
context: validator.currentForm,
@@ -1599,7 +1634,6 @@ $.extend( $.validator, {
15991634
validator.settings.messages[ element.name ][ method ] = previous.originalMessage;
16001635
if ( valid ) {
16011636
submitted = validator.formSubmitted;
1602-
validator.resetInternals();
16031637
validator.toHide = validator.errorsFor( element );
16041638
validator.formSubmitted = submitted;
16051639
validator.successList.push( element );
@@ -1624,6 +1658,7 @@ $.extend( $.validator, {
16241658

16251659
// Ajax mode: abort
16261660
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
1661+
// $.ajaxAbort( port );
16271662
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()
16281663

16291664
var pendingRequests = {},
@@ -1634,9 +1669,7 @@ if ( $.ajaxPrefilter ) {
16341669
$.ajaxPrefilter( function( settings, _, xhr ) {
16351670
var port = settings.port;
16361671
if ( settings.mode === "abort" ) {
1637-
if ( pendingRequests[ port ] ) {
1638-
pendingRequests[ port ].abort();
1639-
}
1672+
$.ajaxAbort( port );
16401673
pendingRequests[ port ] = xhr;
16411674
}
16421675
} );
@@ -1648,14 +1681,20 @@ if ( $.ajaxPrefilter ) {
16481681
var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
16491682
port = ( "port" in settings ? settings : $.ajaxSettings ).port;
16501683
if ( mode === "abort" ) {
1651-
if ( pendingRequests[ port ] ) {
1652-
pendingRequests[ port ].abort();
1653-
}
1684+
$.ajaxAbort( port );
16541685
pendingRequests[ port ] = ajax.apply( this, arguments );
16551686
return pendingRequests[ port ];
16561687
}
16571688
return ajax.apply( this, arguments );
16581689
};
16591690
}
1691+
1692+
// Abort the previous request without sending a new one
1693+
$.ajaxAbort = function( port ) {
1694+
if ( pendingRequests[ port ] ) {
1695+
pendingRequests[ port ].abort();
1696+
delete pendingRequests[ port ];
1697+
}
1698+
};
16601699
return $;
16611700
}));

src/Identity/UI/src/assets/V5/lib/jquery-validation/dist/jquery.validate.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)