@@ -82,7 +82,7 @@ export default class BrowserSolver {
8282
8383 let tool = this . _req . tool ;
8484 result . tool = { id : tool . id } ;
85- if ( ! error && tool . input != null ) {
85+ if ( ! error || error . warning && tool . input != null ) {
8686 let str = Utils . unescSubstStr ( tool . input ) ;
8787 result . tool . result = ( tool . id === "replace" ) ? this . _getReplace ( str ) : this . _getList ( str ) ;
8888 }
@@ -94,6 +94,7 @@ export default class BrowserSolver {
9494 }
9595
9696 _getList ( str ) {
97+ // TODO: should we move this into a worker?
9798 let source = this . _req . text , result = "" , repl , ref , trimR = 0 , regex ;
9899
99100 // build a RegExp without the global flag:
@@ -107,14 +108,14 @@ export default class BrowserSolver {
107108 trimR = str . length ;
108109 str = "$&" + str ;
109110 }
110- while ( true ) {
111- ref = source . replace ( regex , "\b" ) ;
112- let index = ref . indexOf ( "\b" ) ;
113- if ( index === - 1 || ref . length > source . length ) { break ; }
111+ do {
112+ ref = source . replace ( regex , "\b" ) ; // bell char - just a placeholder to find
113+ let index = ref . indexOf ( "\b" ) , empty = ( ref . length > source . length ) ;
114+ if ( index === - 1 ) { break ; }
114115 repl = source . replace ( regex , str ) ;
115116 result += repl . substr ( index , repl . length - ref . length + 1 ) ;
116- source = ref . substr ( index + 1 ) ;
117- }
117+ source = ref . substr ( index + ( empty ? 2 : 1 ) ) ;
118+ } while ( source . length ) ;
118119 if ( trimR ) { result = result . substr ( 0 , result . length - trimR ) ; }
119120 return result ;
120121 }
0 commit comments