File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -173,9 +173,15 @@ export class MatTableDataSource<T> extends DataSource<T> {
173
173
*/
174
174
filterPredicate : ( ( data : T , filter : string ) => boolean ) = ( data : T , filter : string ) : boolean => {
175
175
// Transform the data into a lowercase string of all property values.
176
- const accumulator =
177
- ( currentTerm : string , key : string ) => currentTerm + ( data as { [ key : string ] : any } ) [ key ] ;
178
- const dataStr = Object . keys ( data ) . reduce ( accumulator , '' ) . toLowerCase ( ) ;
176
+ const dataStr = Object . keys ( data ) . reduce ( ( currentTerm : string , key : string ) => {
177
+ // Use an obscure Unicode character to delimit the words in the concatenated string.
178
+ // This avoids matches where the values of two columns combined will match the user's query
179
+ // (e.g. `Flute` and `Stop` will match `Test`). The character is intended to be something
180
+ // that has a very low chance of being typed in by somebody in a text field. This one in
181
+ // particular is "White up-pointing triangle with dot" from
182
+ // https://en.wikipedia.org/wiki/List_of_Unicode_characters
183
+ return currentTerm + ( data as { [ key : string ] : any } ) [ key ] + '◬' ;
184
+ } , '' ) . toLowerCase ( ) ;
179
185
180
186
// Transform the filter by converting it to lowercase and removing whitespace.
181
187
const transformedFilter = filter . trim ( ) . toLowerCase ( ) ;
Original file line number Diff line number Diff line change @@ -259,6 +259,18 @@ describe('MatTable', () => {
259
259
] ) ;
260
260
} ) ) ;
261
261
262
+ it ( 'should not match concatenated words' , fakeAsync ( ( ) => {
263
+ // Set the value to the last character of the first
264
+ // column plus the first character of the second column.
265
+ dataSource . filter = '1b' ;
266
+ fixture . detectChanges ( ) ;
267
+ expect ( dataSource . filteredData . length ) . toBe ( 0 ) ;
268
+ expectTableToMatchContent ( tableElement , [
269
+ [ 'Column A' , 'Column B' , 'Column C' ] ,
270
+ [ 'Footer A' , 'Footer B' , 'Footer C' ] ,
271
+ ] ) ;
272
+ } ) ) ;
273
+
262
274
it ( 'should be able to sort the table contents' , ( ) => {
263
275
// Activate column A sort
264
276
component . sort . sort ( component . sortHeader ) ;
You can’t perform that action at this time.
0 commit comments