File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,8 @@ wordDiff.equals = function(left, right) {
32
32
return left === right || ( this . options . ignoreWhitespace && ! reWhitespace . test ( left ) && ! reWhitespace . test ( right ) ) ;
33
33
} ;
34
34
wordDiff . tokenize = function ( value ) {
35
- let tokens = value . split ( / ( \s + | [ ( ) [ \] { } ' " ] | \b ) / ) ;
35
+ // All whitespace symbols except newline group into one token, each newline - in separate token
36
+ let tokens = value . split ( / ( [ ^ \S \r \n ] + | [ ( ) [ \] { } ' " \r \n ] | \b ) / ) ;
36
37
37
38
// Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
38
39
for ( let i = 0 ; i < tokens . length - 1 ; i ++ ) {
Original file line number Diff line number Diff line change @@ -209,6 +209,15 @@ describe('WordDiff', function() {
209
209
expect ( convertChangesToXML ( diffResult ) ) . to . equal ( '"<ins>word</ins>"' ) ;
210
210
} ) ;
211
211
212
+ it ( 'should threat newline as separate token (issues #180, #211)' , function ( ) {
213
+ // #180
214
+ const diffResult1 = diffWordsWithSpace ( 'foo\nbar' , 'foo\n\n\nbar' ) ;
215
+ expect ( convertChangesToXML ( diffResult1 ) ) . to . equal ( 'foo\n<ins>\n\n</ins>bar' ) ;
216
+ // #211
217
+ const diffResult2 = diffWordsWithSpace ( 'A\n\nB\n' , 'A\nB\n' ) ;
218
+ expect ( convertChangesToXML ( diffResult2 ) ) . to . equal ( 'A\n<del>\n</del>B\n' ) ;
219
+ } ) ;
220
+
212
221
it ( 'should perform async operations' , function ( done ) {
213
222
diffWordsWithSpace ( 'New Value ' , 'New ValueMoreData ' , function ( err , diffResult ) {
214
223
expect ( convertChangesToXML ( diffResult ) ) . to . equal ( 'New<ins> ValueMoreData</ins> <del>Value </del>' ) ;
You can’t perform that action at this time.
0 commit comments