@@ -6,8 +6,6 @@ var util = require("util");
66var url = require ( "url" ) ;
77var XRegExp = require ( './xregexp-all.js' ) ;
88
9- XRegExp . install ( 'natives' ) ;
10-
119function h ( unsafe )
1210{
1311 if ( unsafe == null )
@@ -267,7 +265,7 @@ function serveTest(query, response)
267265
268266 try
269267 {
270- compileTest = new XRegExp ( str_regex , str_options ) ;
268+ compileTest = XRegExp ( str_regex , str_options ) ;
271269 }
272270 catch ( err )
273271 {
@@ -278,7 +276,7 @@ function serveTest(query, response)
278276 html . push ( '</td>\n' ) ;
279277 html . push ( '\t</tr>\n' ) ;
280278 html . push ( '</table>\n' ) ;
281- response . write ( JSON . stringify ( { "success" : false , "message" : "unable to create XRegExp object" , "html" : html . join ( "" ) } ) ) ;
279+ response . write ( JSON . stringify ( { "success" : false , "message" : "Unable to create XRegExp object: " + err . message , "html" : html . join ( "" ) } ) ) ;
282280 response . end ( ) ;
283281 return ;
284282 }
@@ -290,11 +288,11 @@ function serveTest(query, response)
290288 html . push ( "\t\t<tr>\n" ) ;
291289 html . push ( "\t\t\t<th style=\"text-align:center;\">Test</th>\n" ) ;
292290 html . push ( "\t\t\t<th>Input</th>" ) ;
293- html . push ( "\t\t\t<th>input .replace()</th>" ) ;
294- html . push ( "\t\t\t<th>input .split()[]</th>" ) ;
295- html . push ( "\t\t\t<th>regex .test()</th>" ) ;
296- html . push ( "\t\t\t<th>regex .exec().index</th>" ) ;
297- html . push ( "\t\t\t<th>regex .exec()[]</th>" ) ;
291+ html . push ( "\t\t\t<th>XRegExp .replace()</th>" ) ;
292+ html . push ( "\t\t\t<th>XRegExp .split()[]</th>" ) ;
293+ html . push ( "\t\t\t<th>XRegExp .test()</th>" ) ;
294+ html . push ( "\t\t\t<th>XRegExp .exec().index</th>" ) ;
295+ html . push ( "\t\t\t<th>XRegExp .exec()[]</th>" ) ;
298296 html . push ( "\t\t\t<th>regex.lastIndex</th>" ) ;
299297 html . push ( "\t\t</tr>\n" ) ;
300298 html . push ( "\t</thead>\n" ) ;
@@ -325,11 +323,11 @@ function serveTest(query, response)
325323 html . push ( "</td>\n" ) ;
326324
327325 html . push ( '\t\t\t<td>' ) ;
328- html . push ( h ( input . replace ( new XRegExp ( str_regex , str_options ) , replacement == null ? "" : replacement ) ) ) ;
326+ html . push ( h ( XRegExp . replace ( input , XRegExp ( str_regex , str_options ) , replacement == null ? "" : replacement ) ) ) ;
329327 html . push ( "</td>\n" ) ;
330328
331329 html . push ( '\t\t\t<td>' ) ;
332- var splits = input . split ( new XRegExp ( str_regex , str_options ) ) ;
330+ var splits = XRegExp . split ( input , XRegExp ( str_regex , str_options ) ) ;
333331 for ( var split = 0 ; split < splits . length ; split ++ )
334332 {
335333 html . push ( "[" ) ;
@@ -341,11 +339,11 @@ function serveTest(query, response)
341339 html . push ( "</td>\n" ) ;
342340
343341 html . push ( '\t\t\t<td>' ) ;
344- html . push ( new XRegExp ( str_regex , str_options ) . test ( input ) ? "true" : "false" ) ; // can't use the same object twice
342+ html . push ( XRegExp . test ( input , XRegExp ( str_regex , str_options ) ) ? "true" : "false" ) ;
345343 html . push ( "</td>\n" ) ;
346344
347- var regex = new XRegExp ( str_regex , str_options ) ;
348- var result = regex . exec ( input ) ;
345+ var regex = XRegExp ( str_regex , str_options ) ;
346+ var result = XRegExp . exec ( input , regex ) ;
349347 if ( result == null )
350348 {
351349 html . push ( '\t\t\t<td colspan="6"><i>(null)</i></td>\n' ) ;
@@ -364,7 +362,7 @@ function serveTest(query, response)
364362 {
365363 html . push ( "</tr>\n" ) ;
366364 html . push ( '\t\t\t<td colspan="5" style="text-align:right;">' ) ;
367- html . push ( "regex .exec()" ) ;
365+ html . push ( "XRegExp .exec()" ) ;
368366 html . push ( "</td>\n" ) ;
369367 }
370368
@@ -381,13 +379,28 @@ function serveTest(query, response)
381379 html . push ( result [ capture ] == null ? "<i>(null)</i>" : h ( result [ capture ] ) ) ;
382380 html . push ( "<br/>" ) ;
383381 }
382+ if ( result . groups ) {
383+ var captureNames = Object . keys ( result . groups ) ;
384+ for ( var namedCapture = 0 ; namedCapture < captureNames . length ; namedCapture ++ )
385+ {
386+ var key = captureNames [ namedCapture ] ;
387+ html . push ( "groups." ) ;
388+ html . push ( key ) ;
389+ html . push ( ": " ) ;
390+ html . push ( result . groups [ key ] == null ? "<i>(null)</i>" : h ( result . groups [ key ] ) ) ;
391+ html . push ( "<br/>" ) ;
392+ }
393+ }
384394 html . push ( "</td>\n" ) ;
385395
386396 html . push ( '\t\t\t<td>' ) ;
387397 html . push ( regex . lastIndex ) ;
388398 html . push ( "</td>\n" ) ;
389399
390- result = global ? regex . exec ( input ) : null ;
400+ // Avoid an infinite loop for zero-length matches
401+ var pos = result . index + ( result [ 0 ] . length || 1 ) ;
402+
403+ result = global ? XRegExp . exec ( input , regex , pos ) : null ;
391404 }
392405
393406 }
0 commit comments