Skip to content

Commit

Permalink
Fixed match regex
Browse files Browse the repository at this point in the history
  • Loading branch information
engineering-this authored and msamsel committed Aug 3, 2018
1 parent d358f3a commit b264124
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions plugins/emoji/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@

function matchCallback( text, offset ) {
var left = text.slice( 0, offset ),
// Positive lookbehind for space, as emoji should be started with space or newline (#2195).
match = left.match( new RegExp( '(?<=\\s\|^):\\S{' + charactersToStart + '}\\S*$' ) );
// Emoji should be started with space or newline, but space shouldn't leak to output, hence it is in non captured group (#2195).
match = left.match( new RegExp( '(?:\\s\|^)(:\\S{' + charactersToStart + '}\\S*)$' ) );

if ( !match ) {
return null;
}

return { start: match.index, end: offset };
// In case of space preceding colon we need to return index of capturing grup.
return { start: text.indexOf( match[ 1 ] ), end: offset };
}

function dataCallback( matchInfo, callback ) {
Expand Down

0 comments on commit b264124

Please sign in to comment.