Skip to content

Commit

Permalink
fix: display of regex strings as special chars
Browse files Browse the repository at this point in the history
  • Loading branch information
HardeepAsrani committed Dec 20, 2024
1 parent 1f06de3 commit cf548d5
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion js/Conditions/conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,25 @@ const App = () => {
const field = document.getElementById( 'feed-post-filters-conditions' );
if ( field && field.value ) {
const parsedConditions = JSON.parse( field.value );
setConditions( parsedConditions && parsedConditions.conditions ? parsedConditions : { conditions: [], match: 'all' } );
if ( parsedConditions && parsedConditions.conditions ) {
parsedConditions.conditions = parsedConditions.conditions.map( condition => {
// We do all these schananigans to make sure we JS doesn't confuse regex for special characters.
if ( typeof condition.value === 'string' ) {
condition.value = condition.value
.replace( /\u0008/g, '\\b' )
.replace( /\u000C/g, '\\f' )
.replace( /\n/g, '\\n' )
.replace( /\r/g, '\\r' )
.replace( /\t/g, '\\t' );
}
return condition;
} );
setConditions( parsedConditions );
} else {
setConditions( { conditions: [], match: 'all' } );
}
} else {
setConditions( { conditions: [], match: 'all' } );
}
}, [] );

Expand Down

0 comments on commit cf548d5

Please sign in to comment.