Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Infrastructure] Update jquery validate periodically #56725

Merged
merged 17 commits into from
Jul 16, 2024
Merged
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
54 changes: 54 additions & 0 deletions .github/workflows/update-jquery-validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Update jquery-validation

on:
schedule:
- cron: '0 0 1 * *' # Run on the first day of the month
workflow_dispatch: # Allow manual runs

permissions:
contents: write
issues: write
pull-requests: write

jobs:
update-jquery-validate:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Set RepoRoot
run: echo "RepoRoot=$(pwd)" >> $GITHUB_ENV

- name: Update dependencies
working-directory: ${{ env.RepoRoot }}/src/Mvc/build
run: |
npm install --no-lockfile
npm run build
npm run update-identity-ui-scripts
echo "JQUERY_VALIDATE_VERSION=$(npm ls jquery-validation --json | jq -r '.dependencies["jquery-validation"].version')" >> $GITHUB_ENV

- name: Update script tags
working-directory: ${{ env.RepoRoot }}/src/Identity/UI
run: node update-jquery-validate.mjs

- name: Create Pull Request
uses: dotnet/actions-create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Update jquery.validate to ${{ env.JQUERY_VALIDATE_VERSION }}
title: '[Templates][Identity] Update jquery-validation to ${{ env.JQUERY_VALIDATE_VERSION }}'
body: |
Updates the jquery-validation scripts to ${{ env.JQUERY_VALIDATE_VERSION }}
branch: update-jquery-validate-to-${{ env.JQUERY_VALIDATE_VERSION }}
paths: |
**/jquery.validate.js
**/jquery.validate.min.js
**/*.cshtml
src/Identity/UI/jquery-validate-versions.json
4 changes: 4 additions & 0 deletions src/Identity/UI/jquery-validate-versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"currentVersion": "1.20.0",
"integrity": "sha256-ic6hxNWCB3IBDsXq0z5KpKHmcJc1anmnh0xGOi0C5Dw="
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<script src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
</environment>
<environment exclude="Development">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.5/jquery.validate.min.js"
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.20.0/jquery.validate.min.js"
asp-fallback-src="~/Identity/lib/jquery-validation/dist/jquery.validate.min.js"
asp-fallback-test="window.jQuery && window.jQuery.validator"
crossorigin="anonymous"
integrity="sha256-JwUksNJ6/R07ZiLRoXbGeNrtlFZMFDKX4hemPiHOmCA=">
integrity="sha256-ic6hxNWCB3IBDsXq0z5KpKHmcJc1anmnh0xGOi0C5Dw=">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/4.0.0/jquery.validate.unobtrusive.min.js"
asp-fallback-src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<script src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
</environment>
<environment exclude="Development">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.5/jquery.validate.min.js"
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.20.0/jquery.validate.min.js"
asp-fallback-src="~/Identity/lib/jquery-validation/dist/jquery.validate.min.js"
asp-fallback-test="window.jQuery && window.jQuery.validator"
crossorigin="anonymous"
integrity="sha256-JwUksNJ6/R07ZiLRoXbGeNrtlFZMFDKX4hemPiHOmCA=">
integrity="sha256-ic6hxNWCB3IBDsXq0z5KpKHmcJc1anmnh0xGOi0C5Dw=">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/4.0.0/jquery.validate.unobtrusive.min.js"
asp-fallback-src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*!
* jQuery Validation Plugin v1.19.5
* jQuery Validation Plugin v1.20.0
*
* https://jqueryvalidation.org/
*
* Copyright (c) 2022 Jörn Zaefferer
* Copyright (c) 2023 Jörn Zaefferer
* Released under the MIT license
*/
(function( factory ) {
Expand Down Expand Up @@ -774,6 +774,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" ) {
Expand Down Expand Up @@ -960,14 +963,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;
Expand Down Expand Up @@ -1113,6 +1125,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++;
Expand Down Expand Up @@ -1148,6 +1164,25 @@ $.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 ];
$( element ).removeClass( this.settings.pendingClass );
}
},

previousValue: function( element, method ) {
method = typeof method === "string" && method || "remote";

Expand Down Expand Up @@ -1588,7 +1623,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,
Expand All @@ -1599,7 +1634,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 );
Expand All @@ -1624,6 +1658,7 @@ $.extend( $.validator, {

// 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 = {},
Expand All @@ -1634,9 +1669,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;
}
} );
Expand All @@ -1648,14 +1681,20 @@ 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 ];
}
};
return $;
}));

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*!
* jQuery Validation Plugin v1.19.5
* jQuery Validation Plugin v1.20.0
*
* https://jqueryvalidation.org/
*
* Copyright (c) 2022 Jörn Zaefferer
* Copyright (c) 2023 Jörn Zaefferer
* Released under the MIT license
*/
(function( factory ) {
Expand Down Expand Up @@ -774,6 +774,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" ) {
Expand Down Expand Up @@ -960,14 +963,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;
Expand Down Expand Up @@ -1113,6 +1125,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++;
Expand Down Expand Up @@ -1148,6 +1164,25 @@ $.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 ];
$( element ).removeClass( this.settings.pendingClass );
}
},

previousValue: function( element, method ) {
method = typeof method === "string" && method || "remote";

Expand Down Expand Up @@ -1588,7 +1623,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,
Expand All @@ -1599,7 +1634,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 );
Expand All @@ -1624,6 +1658,7 @@ $.extend( $.validator, {

// 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 = {},
Expand All @@ -1634,9 +1669,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;
}
} );
Expand All @@ -1648,14 +1681,20 @@ 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 ];
}
};
return $;
}));

Large diffs are not rendered by default.

Loading
Loading