File tree Expand file tree Collapse file tree 4 files changed +18
-24
lines changed Expand file tree Collapse file tree 4 files changed +18
-24
lines changed Original file line number Diff line number Diff line change @@ -565,6 +565,10 @@ public function save_feedzy_import_feed_meta( $post_id, $post ) {
565
565
$ data_meta ['import_auto_translation ' ] = isset ( $ data_meta ['import_auto_translation ' ] ) ? $ data_meta ['import_auto_translation ' ] : 'no ' ;
566
566
// Check feeds external image URL checkbox checked OR not.
567
567
$ data_meta ['import_use_external_image ' ] = isset ( $ data_meta ['import_use_external_image ' ] ) ? $ data_meta ['import_use_external_image ' ] : 'no ' ;
568
+ // If it is filter_conditions we want to escape it.
569
+ if ( isset ( $ data_meta ['filter_conditions ' ] ) ) {
570
+ $ data_meta ['filter_conditions ' ] = wp_slash ( $ data_meta ['filter_conditions ' ] );
571
+ }
568
572
569
573
// $data_meta['feedzy_post_author'] should be the author username. We convert it to the author ID.
570
574
if ( ! empty ( $ data_meta ['import_post_author ' ] ) ) {
Original file line number Diff line number Diff line change @@ -219,11 +219,10 @@ public function is_condition_met( $condition, $value ): bool {
219
219
}
220
220
break ;
221
221
case self ::OPERATOR_REGEX :
222
- $ regex_pattern = $ condition_value ;
223
222
if ( ! preg_match ( '/^\/.*\/[imsxuADU]*$/ ' , $ condition_value ) ) {
224
- $ regex_pattern = '/ ' . $ condition_value . '/i ' ;
223
+ $ condition_value = '/ ' . $ condition_value . '/i ' ;
225
224
}
226
- return preg_match ( $ regex_pattern , $ value ) === 1 ;
225
+ return preg_match ( $ condition_value , $ value ) === 1 ;
227
226
default :
228
227
// Default is self::OPERATOR_HAS_VALUE
229
228
return ! empty ( $ value );
Original file line number Diff line number Diff line change @@ -36,27 +36,11 @@ const App = () => {
36
36
const field = document . getElementById ( 'feed-post-filters-conditions' ) ;
37
37
if ( field && field . value ) {
38
38
const parsedConditions = JSON . parse ( field . value ) ;
39
- if ( parsedConditions && parsedConditions . conditions ) {
40
- parsedConditions . conditions = parsedConditions . conditions . map (
41
- ( condition ) => {
42
- // We do all these schananigans to make sure we JS doesn't confuse regex for special characters.
43
- if ( typeof condition . value === 'string' ) {
44
- condition . value = condition . value
45
- . replace ( / \u0008 / g, '\\b' )
46
- . replace ( / \u000C / g, '\\f' )
47
- . replace ( / \n / g, '\\n' )
48
- . replace ( / \r / g, '\\r' )
49
- . replace ( / \t / g, '\\t' ) ;
50
- }
51
- return condition ;
52
- }
53
- ) ;
54
- setConditions ( parsedConditions ) ;
55
- } else {
56
- setConditions ( { conditions : [ ] , match : 'all' } ) ;
57
- }
58
- } else {
59
- setConditions ( { conditions : [ ] , match : 'all' } ) ;
39
+ setConditions (
40
+ parsedConditions && parsedConditions . conditions
41
+ ? parsedConditions
42
+ : { conditions : [ ] , match : 'all' }
43
+ ) ;
60
44
}
61
45
} , [ ] ) ;
62
46
Original file line number Diff line number Diff line change @@ -145,5 +145,12 @@ public function test_is_condition_met_regex() {
145
145
'value ' => '/test/ ' ,
146
146
);
147
147
$ this ->assertTrue ( $ this ->conditions ->is_condition_met ( $ condition , 'this is a test ' ) );
148
+
149
+
150
+ $ condition = array (
151
+ 'operator ' => 'regex ' ,
152
+ 'value ' => '\band\b ' ,
153
+ );
154
+ $ this ->assertTrue ( $ this ->conditions ->is_condition_met ( $ condition , 'matt and tommy ' ) );
148
155
}
149
156
}
You can’t perform that action at this time.
0 commit comments