Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
41066154
Commit
41066154
authored
Aug 03, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
4f45b2bb
7a87c69d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
1 deletion
+58
-1
Handler.java
...ain/java/org/springframework/boot/loader/jar/Handler.java
+28
-1
HandlerTests.java
...ava/org/springframework/boot/loader/jar/HandlerTests.java
+30
-0
No files found.
spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java
View file @
41066154
...
...
@@ -203,7 +203,34 @@ public class Handler extends URLStreamHandler {
}
private
void
setFile
(
URL
context
,
String
file
)
{
setURL
(
context
,
JAR_PROTOCOL
,
null
,
-
1
,
null
,
null
,
file
,
null
,
null
);
setURL
(
context
,
JAR_PROTOCOL
,
null
,
-
1
,
null
,
null
,
normalize
(
file
),
null
,
null
);
}
private
String
normalize
(
String
file
)
{
int
afterLastSeparatorIndex
=
file
.
lastIndexOf
(
SEPARATOR
)
+
SEPARATOR
.
length
();
String
afterSeparator
=
file
.
substring
(
afterLastSeparatorIndex
);
afterSeparator
=
replaceParentDir
(
afterSeparator
);
afterSeparator
=
replaceCurrentDir
(
afterSeparator
);
return
file
.
substring
(
0
,
afterLastSeparatorIndex
)
+
afterSeparator
;
}
private
String
replaceParentDir
(
String
file
)
{
int
parentDirIndex
;
while
((
parentDirIndex
=
file
.
indexOf
(
"/../"
))
>=
0
)
{
int
precedingSlashIndex
=
file
.
lastIndexOf
(
'/'
,
parentDirIndex
-
1
);
if
(
precedingSlashIndex
>=
0
)
{
file
=
file
.
substring
(
0
,
precedingSlashIndex
)
+
file
.
substring
(
parentDirIndex
+
3
);
}
else
{
file
=
file
.
substring
(
parentDirIndex
+
4
);
}
}
return
file
;
}
private
String
replaceCurrentDir
(
String
file
)
{
return
file
.
replace
(
"/./"
,
"/"
);
}
@Override
...
...
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/HandlerTests.java
View file @
41066154
...
...
@@ -136,6 +136,36 @@ public class HandlerTests {
new
URL
(
"jar:file:/test.jar!/BOOT-INF/classes/foo.txt"
)));
}
@Test
public
void
urlWithSpecReferencingParentDirectory
()
throws
MalformedURLException
{
assertStandardAndCustomHandlerUrlsAreEqual
(
"file:/test.jar!/BOOT-INF/classes!/xsd/folderA/a.xsd"
,
"../folderB/b.xsd"
);
}
@Test
public
void
urlWithSpecReferencingAncestorDirectoryOutsideJarStopsAtJarRoot
()
throws
MalformedURLException
{
assertStandardAndCustomHandlerUrlsAreEqual
(
"file:/test.jar!/BOOT-INF/classes!/xsd/folderA/a.xsd"
,
"../../../../../../folderB/b.xsd"
);
}
@Test
public
void
urlWithSpecReferencingCurrentDirectory
()
throws
MalformedURLException
{
assertStandardAndCustomHandlerUrlsAreEqual
(
"file:/test.jar!/BOOT-INF/classes!/xsd/folderA/a.xsd"
,
"./folderB/./b.xsd"
);
}
private
void
assertStandardAndCustomHandlerUrlsAreEqual
(
String
context
,
String
spec
)
throws
MalformedURLException
{
URL
standardUrl
=
new
URL
(
new
URL
(
"jar:"
+
context
),
spec
);
URL
customHandlerUrl
=
new
URL
(
new
URL
(
"jar"
,
null
,
-
1
,
context
,
this
.
handler
),
spec
);
assertThat
(
customHandlerUrl
.
toString
()).
isEqualTo
(
standardUrl
.
toString
());
}
private
URL
createUrl
(
String
file
)
throws
MalformedURLException
{
return
new
URL
(
"jar"
,
null
,
-
1
,
file
,
this
.
handler
);
}
...
...
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