@@ -462,32 +462,56 @@ function initial_request(user, repo) {
462462}
463463
464464/** Extracts and sanitizes 'user' and 'repo' values from potential inputs. */
465- function initiate_search ( ) {
465+ function parse_query ( queryString ) {
466+ const shorthand = / ^ (?< user > [ \w . - ] + ) \/ (?< repo > [ \w . - ] + ) $ / ;
467+ const shorthandMatch = shorthand . exec ( queryString ) ;
468+
469+ if ( shorthandMatch ) { // we are dealing with "user/repo" input format
470+ const { user, repo} = shorthandMatch . groups ;
471+ return { user, repo} ;
472+ }
473+
474+ let pathname ;
475+ try {
476+ pathname = new URL ( queryString ) . pathname ;
477+ } catch {
478+ return null ;
479+ }
480+
481+ const values = pathname . split ( '/' ) . filter ( s => s . length > 0 ) ;
482+ if ( values . length < 2 )
483+ return null ;
466484
485+ const [ user , repo ] = values ;
486+ return { user, repo} ;
487+ }
488+
489+
490+ function initiate_search ( ) {
467491 /* Checking if search is allowed. */
468492 if ( searchNotAllowed ( ) )
469493 return ; // abort
470494
471495 clear_old_data ( ) ;
472496
473497 let queryString = getQueryOrDefault ( "payne911/PieMenu" ) ;
474- let queryValues = queryString . split ( '/' ) . filter ( Boolean ) ;
498+ const queryValues = parse_query ( queryString ) ;
475499
476- let len = queryValues . length ;
477- if ( len < 2 ) {
478- setMsg ( 'Please enter a valid query: it should contain two strings separated by a "/"' ) ;
500+ if ( ! queryValues ) {
501+ setMsg ( 'Please enter a valid query: it should contain two strings separated by a "/", or the full URL to a GitHub repo' ) ;
479502 ga_faultyQuery ( queryString ) ;
480503 return ; // abort
481504 }
482505
506+ const { user, repo} = queryValues ;
507+
483508 setUpOctokitWithLatestToken ( ) ;
484509
510+ setQuery ( `${ user } /${ repo } ` ) ;
485511 setQueryFieldsAsLoading ( ) ;
486512 hideFilterContainer ( ) ;
487513 setMsg ( UF_MSG_SCANNING ) ;
488514
489- const user = queryValues [ len - 2 ] ;
490- const repo = queryValues [ len - 1 ] ;
491515 if ( history . replaceState ) {
492516 history . replaceState ( { } , document . title , `?repo=${ user } /${ repo } ` ) ; // replace current URL param
493517 }
0 commit comments