This repository was archived by the owner on Jun 21, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed
Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ public class GitHubContextService
3535 static readonly Regex windowTitlePathRegex = new Regex ( $ "{ path } at { branch } · { owner } /{ repo } ( · GitHub)? - ", RegexOptions . Compiled ) ;
3636 static readonly Regex windowTitleBranchesRegex = new Regex ( $ "Branches · { owner } /{ repo } ( · GitHub)? - ", RegexOptions . Compiled ) ;
3737
38+ static readonly Regex urlLineRegex = new Regex ( $ "#L(?<line>[0-9]+)$", RegexOptions . Compiled ) ;
39+
3840 public GitHubContext FindContextFromUrl ( string url )
3941 {
4042 var uri = new UriString ( url ) ;
@@ -158,20 +160,16 @@ public GitHubContext FindContextFromWindowTitle(string windowTitle)
158160
159161 static int ? FindLine ( UriString gitHubUrl )
160162 {
161- var prefix = "#L" ;
162163 var url = gitHubUrl . ToString ( ) ;
163- var index = url . LastIndexOf ( prefix ) ;
164- if ( index == - 1 )
165- {
166- return null ;
167- }
168164
169- if ( ! int . TryParse ( url . Substring ( index + prefix . Length ) , out int lineNumber ) )
165+ var match = urlLineRegex . Match ( url ) ;
166+ if ( match . Success )
170167 {
171- return null ;
168+ int . TryParse ( match . Groups [ "line" ] . Value , out int line ) ;
169+ return line ;
172170 }
173171
174- return lineNumber ; // 1 based
172+ return null ;
175173 }
176174
177175 string FindPath ( UriString uri )
You can’t perform that action at this time.
0 commit comments