github.com/ndarilek/terraform@v0.3.8-0.20150320140257-d3135c1b2bac/helper/url/url_windows.go (about)

     1  package url
     2  
     3  import (
     4  	"fmt"
     5  	"net/url"
     6  	"path/filepath"
     7  	"strings"
     8  )
     9  
    10  func parse(rawURL string) (*url.URL, error) {
    11  	// Make sure we're using "/" since URLs are "/"-based.
    12  	rawURL = filepath.ToSlash(rawURL)
    13  
    14  	u, err := url.Parse(rawURL)
    15  	if err != nil {
    16  		return nil, err
    17  	}
    18  
    19  	if len(rawURL) > 1 && rawURL[1] == ':' {
    20  		// Assume we're dealing with a drive letter file path where the drive
    21  		// letter has been parsed into the URL Scheme, and the rest of the path
    22  		// has been parsed into the URL Path without the leading ':' character.
    23  		u.Path = fmt.Sprintf("%s:%s", string(rawURL[0]), u.Path)
    24  		u.Scheme = ""
    25  	}
    26  
    27  	if len(u.Host) > 1 && u.Host[1] == ':' && strings.HasPrefix(rawURL, "file://") {
    28  		// Assume we're dealing with a drive letter file path where the drive
    29  		// letter has been parsed into the URL Host.
    30  		u.Path = fmt.Sprintf("%s%s", u.Host, u.Path)
    31  		u.Host = ""
    32  	}
    33  
    34  	// Remove leading slash for absolute file paths.
    35  	if len(u.Path) > 2 && u.Path[0] == '/' && u.Path[2] == ':' {
    36  		u.Path = u.Path[1:]
    37  	}
    38  
    39  	return u, err
    40  }