Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
7191c1f2
Commit
7191c1f2
authored
Apr 21, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common: Fix URL parsing issues on Windows
parent
159587da
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
13 deletions
+41
-13
CHANGELOG.md
CHANGELOG.md
+1
-0
common/config.go
common/config.go
+23
-9
common/config_test.go
common/config_test.go
+17
-4
No files found.
CHANGELOG.md
View file @
7191c1f2
...
...
@@ -28,6 +28,7 @@ IMPROVEMENTS:
BUG FIXES:
*
core: Errors are properly shown when adding bad floppy files. [GH-1043]
*
core: Fix some URL parsing issues on Windows.
*
builder/amazon-instance: Use S3Endpoint for ec2-upload-bundle arg,
which works for every region. [GH-904]
*
builder/digitalocean: updated default image_id [GH-1032]
...
...
common/config.go
View file @
7191c1f2
...
...
@@ -101,15 +101,20 @@ func DownloadableURL(original string) (string, error) {
}
if
url
.
Scheme
==
"file"
{
// For Windows absolute file paths, remove leading / prior to processing
// since net/url turns "C:/" into "/C:/"
if
runtime
.
GOOS
==
"windows"
&&
url
.
Path
[
0
]
==
'/'
{
url
.
Path
=
url
.
Path
[
1
:
len
(
url
.
Path
)]
// Windows file handling is all sorts of tricky...
if
runtime
.
GOOS
==
"windows"
{
// If the path is using Windows-style slashes, URL parses
// it into the host field.
if
url
.
Path
==
""
&&
strings
.
Contains
(
url
.
Host
,
`\`
)
{
url
.
Path
=
url
.
Host
url
.
Host
=
""
}
// Also replace all backslashes with forwardslashes since Windows
// users are likely to do this but the URL should actually only
// contain forward slashes.
url
.
Path
=
strings
.
Replace
(
url
.
Path
,
`\`
,
`/`
,
-
1
)
// For Windows absolute file paths, remove leading / prior to processing
// since net/url turns "C:/" into "/C:/"
if
len
(
url
.
Path
)
>
0
&&
url
.
Path
[
0
]
==
'/'
{
url
.
Path
=
url
.
Path
[
1
:
len
(
url
.
Path
)]
}
}
// Only do the filepath transformations if the file appears
...
...
@@ -127,6 +132,13 @@ func DownloadableURL(original string) (string, error) {
url
.
Path
=
filepath
.
Clean
(
url
.
Path
)
}
if
runtime
.
GOOS
==
"windows"
{
// Also replace all backslashes with forwardslashes since Windows
// users are likely to do this but the URL should actually only
// contain forward slashes.
url
.
Path
=
strings
.
Replace
(
url
.
Path
,
`\`
,
`/`
,
-
1
)
}
}
// Make sure it is lowercased
...
...
@@ -195,11 +207,13 @@ func decodeConfigHook(raws []interface{}) (mapstructure.DecodeHookFunc, error) {
},
nil
}
func
CoalesceVals
(
vals
...
string
)
string
{
// ChooseString returns the first non-empty value.
func
ChooseString
(
vals
...
string
)
string
{
for
_
,
el
:=
range
vals
{
if
el
!=
""
{
return
el
}
}
return
""
}
common/config_test.go
View file @
7191c1f2
...
...
@@ -7,6 +7,8 @@ import (
"os"
"path/filepath"
"reflect"
"runtime"
"strings"
"testing"
)
...
...
@@ -141,6 +143,11 @@ func TestDownloadableURL_FilePaths(t *testing.T) {
tfPath
=
filepath
.
Clean
(
tfPath
)
filePrefix
:=
"file://"
if
runtime
.
GOOS
==
"windows"
{
filePrefix
+=
"/"
}
// Relative filepath. We run this test in a func so that
// the defers run right away.
func
()
{
...
...
@@ -161,8 +168,11 @@ func TestDownloadableURL_FilePaths(t *testing.T) {
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
u
!=
fmt
.
Sprintf
(
"file://%s"
,
tfPath
)
{
t
.
Fatalf
(
"unexpected: %s"
,
u
)
expected
:=
fmt
.
Sprintf
(
"%s%s"
,
filePrefix
,
strings
.
Replace
(
tfPath
,
`\`
,
`/`
,
-
1
))
if
u
!=
expected
{
t
.
Fatalf
(
"unexpected: %#v != %#v"
,
u
,
expected
)
}
}()
...
...
@@ -180,8 +190,11 @@ func TestDownloadableURL_FilePaths(t *testing.T) {
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
u
!=
fmt
.
Sprintf
(
"file://%s"
,
tfPath
)
{
t
.
Fatalf
(
"unexpected: %s"
,
u
)
expected
:=
fmt
.
Sprintf
(
"%s%s"
,
filePrefix
,
strings
.
Replace
(
tfPath
,
`\`
,
`/`
,
-
1
))
if
u
!=
expected
{
t
.
Fatalf
(
"unexpected: %s != %s"
,
u
,
expected
)
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment