Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
64fd281f
Commit
64fd281f
authored
Sep 17, 2016
by
Tw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parser: fix broken absolute path imports
fix issue #1026 Signed-off-by:
Tw
<
tw19881113@gmail.com
>
parent
bedad34b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
1 deletion
+100
-1
caddyfile/parse.go
caddyfile/parse.go
+3
-1
caddyfile/parse_test.go
caddyfile/parse_test.go
+97
-0
No files found.
caddyfile/parse.go
View file @
64fd281f
...
...
@@ -260,7 +260,9 @@ func (p *parser) doImport() error {
}
if
token
.
Line
==
importLine
{
var
abs
string
if
!
filepath
.
IsAbs
(
importFile
)
{
if
filepath
.
IsAbs
(
token
.
Text
)
{
abs
=
token
.
Text
}
else
if
!
filepath
.
IsAbs
(
importFile
)
{
abs
=
filepath
.
Join
(
filepath
.
Dir
(
absFile
),
token
.
Text
)
}
else
{
abs
=
filepath
.
Join
(
importDir
,
token
.
Text
)
...
...
caddyfile/parse_test.go
View file @
64fd281f
package
caddyfile
import
(
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
)
...
...
@@ -249,6 +251,101 @@ func TestParseOneAndImport(t *testing.T) {
}
}
func
TestRecursiveImport
(
t
*
testing
.
T
)
{
testParseOne
:=
func
(
input
string
)
(
ServerBlock
,
error
)
{
p
:=
testParser
(
input
)
p
.
Next
()
// parseOne doesn't call Next() to start, so we must
err
:=
p
.
parseOne
()
return
p
.
block
,
err
}
isExpected
:=
func
(
got
ServerBlock
)
bool
{
if
len
(
got
.
Keys
)
!=
1
||
got
.
Keys
[
0
]
!=
"localhost"
{
t
.
Errorf
(
"got keys unexpected: expect localhost, got %v"
,
got
.
Keys
)
return
false
}
if
len
(
got
.
Tokens
)
!=
2
{
t
.
Errorf
(
"got wrong number of tokens: expect 2, got %d"
,
len
(
got
.
Tokens
))
return
false
}
if
len
(
got
.
Tokens
[
"dir1"
])
!=
1
||
len
(
got
.
Tokens
[
"dir2"
])
!=
2
{
t
.
Errorf
(
"got unexpect tokens: %v"
,
got
.
Tokens
)
return
false
}
return
true
}
recursive_file1
,
err
:=
filepath
.
Abs
(
"testdata/recursive_import_test1"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
recursive_file2
,
err
:=
filepath
.
Abs
(
"testdata/recursive_import_test2"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// test relative recursive import
err
=
ioutil
.
WriteFile
(
recursive_file1
,
[]
byte
(
`localhost
dir1
import recursive_import_test2`
),
0644
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
os
.
Remove
(
recursive_file1
)
err
=
ioutil
.
WriteFile
(
recursive_file2
,
[]
byte
(
"dir2 1"
),
0644
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
os
.
Remove
(
recursive_file2
)
// import absolute path
result
,
err
:=
testParseOne
(
"import "
+
recursive_file1
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
isExpected
(
result
)
{
t
.
Error
(
"absolute+relative import failed"
)
}
// import relative path
result
,
err
=
testParseOne
(
"import testdata/recursive_import_test1"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
isExpected
(
result
)
{
t
.
Error
(
"relative+relative import failed"
)
}
// test absolute recursive import
err
=
ioutil
.
WriteFile
(
recursive_file1
,
[]
byte
(
`localhost
dir1
import `
+
recursive_file2
),
0644
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// import absolute path
result
,
err
=
testParseOne
(
"import "
+
recursive_file1
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
isExpected
(
result
)
{
t
.
Error
(
"absolute+absolute import failed"
)
}
// import relative path
result
,
err
=
testParseOne
(
"import testdata/recursive_import_test1"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
isExpected
(
result
)
{
t
.
Error
(
"relative+absolute import failed"
)
}
}
func
TestParseAll
(
t
*
testing
.
T
)
{
for
i
,
test
:=
range
[]
struct
{
input
string
...
...
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