Skip to content

Commit

Permalink
Simplify slug logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sc0ttkclark committed Sep 14, 2024
1 parent 9e46547 commit 95e15fb
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions ui/js/jquery.pods.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,21 +566,20 @@
if ( $slug.length ) {
$slug.on( 'change', function () {
// Strip HTML/code.
var slug = $( this ).val().replace( /<(?:.)*?>/g, '' ).replace( /['"]/g, '' ).replace( /<!--|--!?>/g, '' ).replace( /<|>/g, '' ),
var slug = $( this ).val().replace( /([^0-9a-zA-Z\_\- ])/g, '' ),
nameRaw = $( this ).prop( 'name' ),
name = nameRaw.replace( /\[/g, '\\[' ).replace( /\]/g, '\\]' );

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This does not escape backslash characters in the input.

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This does not escape backslash characters in the input.

if ( slug.length ) {
slug = slug.replace( /_+/g, '_' );
slug = slug.replace( /\-+/g, '-' );

var slug_lower = slug.toLowerCase(),
slug_sanitized = slug.replace( /([^0-9a-zA-Z\_\- ])/g, '' );

slug_sanitized = slug_sanitized.replace( /([_\- ]+)$/g, '' );
slug_sanitized = slug_sanitized.replace( /\s+/g, '_' );
slug_sanitized = slug_sanitized.replace( /-+/g, '-' );
slug_sanitized = slug_sanitized.replace( /_+/g, '_' );
slug = slug.replace(/_+/g, '_')
.replace(/\-+/g, '-');

var slug_lower = slug.toLowerCase(),
slug_sanitized = slug.replace(/([^0-9a-zA-Z\_\- ])/g, '')
.replace(/([_\- ]+)$/g, '')
.replace(/\s+/g, '_')
.replace(/-+/g, '-')
.replace(/_+/g, '_');

var slug_sanitized_lower = slug_sanitized.toLowerCase();

Expand Down

0 comments on commit 95e15fb

Please sign in to comment.