@@ -57,7 +57,11 @@ public DisplayPackageViewModel(Package package, User currentUser, string pushedB
5757 PushedBy = pushedBy ;
5858
5959 InitializeRepositoryMetadata ( package . RepositoryUrl , package . RepositoryType ) ;
60- InitializeProjectUrl ( package . ProjectUrl ) ;
60+
61+ if ( PackageHelper . TryPrepareUrlForRendering ( package . ProjectUrl , out string projectUrl ) )
62+ {
63+ ProjectUrl = projectUrl ;
64+ }
6165 }
6266
6367 public bool ValidatingTooLong { get ; set ; }
@@ -166,17 +170,14 @@ private void InitializeRepositoryMetadata(string repositoryUrl, string repositor
166170 RepositoryUrl = repositoryUrl ;
167171 }
168172
169- if ( IsGitHubUri ( repoUri ) )
173+ if ( repoUri . IsGitHubUri ( ) )
170174 {
171175 RepositoryType = RepositoryKind . GitHub ;
172176
173177 // Fix-up git:// to https:// for GitHub URLs (we should add this fix-up to other repos in the future)
174178 if ( repoUri . IsGitProtocol ( ) )
175179 {
176- var uri = new UriBuilder ( repoUri ) ;
177- uri . Scheme = Uri . UriSchemeHttps ;
178-
179- RepositoryUrl = uri . ToString ( ) ;
180+ RepositoryUrl = repoUri . ToHttps ( ) . ToString ( ) ;
180181 }
181182 }
182183 else if ( PackageHelper . IsGitRepositoryType ( repositoryType ) )
@@ -186,54 +187,6 @@ private void InitializeRepositoryMetadata(string repositoryUrl, string repositor
186187 }
187188 }
188189
189- private void InitializeProjectUrl ( string projectUrlString )
190- {
191- if ( Uri . TryCreate ( projectUrlString , UriKind . Absolute , out var projectUrl ) )
192- {
193- if ( projectUrl . IsHttpProtocol ( ) && IsDomainWithHttpsSupport ( projectUrl ) )
194- {
195- var uri = new UriBuilder ( projectUrl ) ;
196- uri . Scheme = Uri . UriSchemeHttps ;
197- uri . Port = - 1 ;
198-
199- ProjectUrl = uri . ToString ( ) ;
200- }
201- else if ( projectUrl . IsHttpsProtocol ( ) || projectUrl . IsHttpProtocol ( ) )
202- {
203- ProjectUrl = projectUrl . ToString ( ) ;
204- }
205- }
206- }
207-
208- private static bool IsDomainWithHttpsSupport ( Uri uri )
209- {
210- return IsGitHubUri ( uri ) || IsCodeplexUri ( uri ) || IsMicrosoftUri ( uri ) ;
211- }
212-
213- private static bool IsGitHubUri ( Uri uri )
214- {
215- return string . Equals ( uri . Authority , "www.github.com" , StringComparison . OrdinalIgnoreCase ) ||
216- string . Equals ( uri . Authority , "github.com" , StringComparison . OrdinalIgnoreCase ) ||
217- string . Equals ( uri . Authority , "www.github.com:443" , StringComparison . OrdinalIgnoreCase ) ||
218- string . Equals ( uri . Authority , "github.com:443" , StringComparison . OrdinalIgnoreCase ) ;
219- }
220-
221- private static bool IsCodeplexUri ( Uri uri )
222- {
223- return uri . Authority . EndsWith ( ".codeplex.com" , StringComparison . OrdinalIgnoreCase ) ||
224- string . Equals ( uri . Authority , "codeplex.com" , StringComparison . OrdinalIgnoreCase ) ;
225- }
226-
227- private static bool IsMicrosoftUri ( Uri uri )
228- {
229- return uri . Authority . EndsWith ( ".microsoft.com" , StringComparison . OrdinalIgnoreCase ) ||
230- string . Equals ( uri . Authority , "microsoft.com" , StringComparison . OrdinalIgnoreCase ) ||
231- string . Equals ( uri . Authority , "www.asp.net" , StringComparison . OrdinalIgnoreCase ) ||
232- string . Equals ( uri . Authority , "asp.net" , StringComparison . OrdinalIgnoreCase ) ||
233- uri . Authority . EndsWith ( ".msdn.com" , StringComparison . OrdinalIgnoreCase ) ||
234- string . Equals ( uri . Authority , "msdn.com" , StringComparison . OrdinalIgnoreCase ) ;
235- }
236-
237190 public enum RepositoryKind
238191 {
239192 Unknown ,
0 commit comments