File tree Expand file tree Collapse file tree 2 files changed +28
-10
lines changed
Expand file tree Collapse file tree 2 files changed +28
-10
lines changed Original file line number Diff line number Diff line change @@ -502,14 +502,14 @@ impl Options {
502502 if !h. ends_with ( '/' ) {
503503 h. push ( '/' ) ;
504504 }
505- h
505+ h. replace ( " \\ " , "/" )
506506 } ) ;
507507 if let Some ( ref source_code_external_url) = source_code_external_url {
508- if ! source_code_external_url. starts_with ( "http://" )
509- && !source_code_external_url . starts_with ( "https://" )
510- {
511- diag . struct_err ( "option `--source-code-external-url` argument must be an URL" )
512- . emit ( ) ;
508+ if source_code_external_url. starts_with ( "/" ) {
509+ diag . struct_err (
510+ "option `--source-code-external-url` argument cannot be an absolute local path" ,
511+ )
512+ . emit ( ) ;
513513 return Err ( 1 ) ;
514514 }
515515 }
Original file line number Diff line number Diff line change @@ -1553,6 +1553,21 @@ impl Context {
15531553 }
15541554}
15551555
1556+ fn compute_path ( path : String ) -> String {
1557+ if path. split ( '/' ) . find ( |x| * x == ".." ) . is_none ( ) {
1558+ return path;
1559+ }
1560+ let mut new_path = Vec :: new ( ) ;
1561+ for part in path. split ( '/' ) {
1562+ if part == ".." && !new_path. is_empty ( ) {
1563+ new_path. pop ( ) ;
1564+ } else {
1565+ new_path. push ( part) ;
1566+ }
1567+ }
1568+ new_path. join ( "/" )
1569+ }
1570+
15561571impl Context {
15571572 /// Generates a url appropriate for an `href` attribute back to the source of
15581573 /// this item.
@@ -1607,10 +1622,13 @@ impl Context {
16071622 } ;
16081623 if let Some ( ref source_code_external_url) = self . shared . source_code_external_url {
16091624 Some ( format ! (
1610- "{root}{krate}/{path}#{lines}" ,
1611- root = source_code_external_url,
1612- krate = krate,
1613- path = path,
1625+ "{path}#{lines}" ,
1626+ path = compute_path( format!(
1627+ "{root}{krate}/{path}" ,
1628+ root = source_code_external_url,
1629+ krate = krate,
1630+ path = path,
1631+ ) , ) ,
16141632 lines = lines
16151633 ) )
16161634 } else {
You can’t perform that action at this time.
0 commit comments