Skip to content

Commit

Permalink
Improve tag matching
Browse files Browse the repository at this point in the history
Fixes case where tag is followed by punctuation
  • Loading branch information
aduth committed May 21, 2017
1 parent 2fb7619 commit 267aeaa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/state/selectors/get-dones.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export default function getDones( state, query = {} ) {
return includes( pageIds, item.id );

case 'tag':
const tag = '#' + value.toLowerCase();
const text = item.text.toLowerCase();
return includes( text.split( ' ' ), tag );
const tag = value.replace( /\W/g, '' );
const pattern = new RegExp( `(^|\\s)#${ tag }(\\W|$)`, 'i' );
return pattern.test( item.text );

default:
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/state/selectors/test/get-dones.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe( 'getDones()', () => {
290: {
id: 290,
user: 1,
text: '#fill #the #tag #cloud',
text: '#fill, #the #tag #cloud',
date: '2017-04-27 00:00:00',
done: true
}
Expand All @@ -41,7 +41,7 @@ describe( 'getDones()', () => {
expect( dones ).to.eql( [ {
id: 290,
user: 1,
text: '#fill #the #tag #cloud',
text: '#fill, #the #tag #cloud',
date: '2017-04-27 00:00:00',
done: true
} ] );
Expand Down

0 comments on commit 267aeaa

Please sign in to comment.