@@ -200,8 +200,9 @@ protected function action($command)
200200 break ;
201201 }
202202 if ($ this ->isEOF ($ this ->a )) {
203+ $ byte = $ this ->inputIndex - 1 ;
203204 throw new JSMin_UnterminatedStringException (
204- "JSMin: Unterminated String at byte {$ this -> inputIndex }: {$ str }" );
205+ "JSMin: Unterminated String at byte {$ byte }: {$ str }" );
205206 }
206207 $ str .= $ this ->a ;
207208 if ($ this ->a === '\\' ) {
@@ -251,8 +252,9 @@ protected function action($command)
251252 $ this ->a = $ this ->get ();
252253 $ pattern .= $ this ->a ;
253254 } elseif ($ this ->isEOF ($ this ->a )) {
255+ $ byte = $ this ->inputIndex - 1 ;
254256 throw new JSMin_UnterminatedRegExpException (
255- "JSMin: Unterminated RegExp at byte {$ this -> inputIndex }: {$ pattern }" );
257+ "JSMin: Unterminated RegExp at byte {$ byte }: {$ pattern }" );
256258 }
257259 $ this ->output .= $ this ->a ;
258260 $ this ->lastByteOut = $ this ->a ;
@@ -272,23 +274,33 @@ protected function isRegexpLiteral()
272274 // we obviously aren't dividing
273275 return true ;
274276 }
275- if ($ this ->a === ' ' || $ this ->a === "\n" ) {
276- $ length = strlen ($ this ->output );
277- if ($ length < 2 ) { // weird edge case
278- return true ;
277+
278+ // we have to check for a preceding keyword, and we don't need to pattern
279+ // match over the whole output.
280+ $ recentOutput = substr ($ this ->output , -10 );
281+
282+ // check if return/typeof directly precede a pattern without a space
283+ foreach (array ('return ' , 'typeof ' ) as $ keyword ) {
284+ if ($ this ->a !== substr ($ keyword , -1 )) {
285+ // certainly wasn't keyword
286+ continue ;
279287 }
280- // you can't divide a keyword
281- if (preg_match ('/(?:case|else|in|return|typeof)$/ ' , $ this ->output , $ m )) {
282- if ($ this ->output === $ m [0 ]) { // odd but could happen
283- return true ;
284- }
285- // make sure it's a keyword, not end of an identifier
286- $ charBeforeKeyword = substr ($ this ->output , $ length - strlen ($ m [0 ]) - 1 , 1 );
287- if (! $ this ->isAlphaNum ($ charBeforeKeyword )) {
288+ if (preg_match ("~(^|[ \\s \\S]) " . substr ($ keyword , 0 , -1 ) . "$~ " , $ recentOutput , $ m )) {
289+ if ($ m [1 ] === '' || !$ this ->isAlphaNum ($ m [1 ])) {
288290 return true ;
289291 }
290292 }
291293 }
294+
295+ // check all keywords
296+ if ($ this ->a === ' ' || $ this ->a === "\n" ) {
297+ if (preg_match ('~(^|[ \\s \\S])(?:case|else|in|return|typeof)$~ ' , $ recentOutput , $ m )) {
298+ if ($ m [1 ] === '' || !$ this ->isAlphaNum ($ m [1 ])) {
299+ return true ;
300+ }
301+ }
302+ }
303+
292304 return false ;
293305 }
294306
0 commit comments