File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ class TextExtraction {
52
52
) ;
53
53
54
54
textLeft = textLeft . substr ( matches . index + matches [ 0 ] . length ) ;
55
- indexOfMatchedString += matches [ 0 ] . length ;
55
+ indexOfMatchedString += matches [ 0 ] . length - 1 ;
56
56
// Global RegExps are stateful, this makes it operate on the "remainder" of the string
57
57
pattern . pattern . lastIndex = indexOfMatchedString ;
58
58
}
Original file line number Diff line number Diff line change @@ -28,6 +28,34 @@ describe('TextExtraction', () => {
28
28
expect ( textExtraction . parse ( ) ) . toEqual ( [ { children : 'abcdef' } ] ) ;
29
29
} ) ;
30
30
31
+ it ( 'still works even if the RegExp has a previously-used pattern' , ( ) => {
32
+ const r = / c / g;
33
+ r . lastIndex = 2 ;
34
+ const textExtraction = new TextExtraction ( 'cc something c something' , [
35
+ { pattern : r , renderText : ( ) => 'Found!' } ,
36
+ ] ) ;
37
+
38
+ expect ( textExtraction . parse ( ) ) . toMatchInlineSnapshot ( `
39
+ Array [
40
+ Object {
41
+ "children": "Found!",
42
+ },
43
+ Object {
44
+ "children": "Found!",
45
+ },
46
+ Object {
47
+ "children": " something ",
48
+ },
49
+ Object {
50
+ "children": "Found!",
51
+ },
52
+ Object {
53
+ "children": " something",
54
+ },
55
+ ]
56
+ ` ) ;
57
+ } ) ;
58
+
31
59
it ( 'returns an array with text parts if there is matches' , ( ) => {
32
60
const textExtraction = new TextExtraction (
33
61
'hello my website is http://foo.bar, bar is good.' ,
You can’t perform that action at this time.
0 commit comments