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
cf27917e
Commit
cf27917e
authored
May 31, 2018
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.0.x'
parents
9ec9a74a
bdd541b2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
3 deletions
+71
-3
JarURLConnection.java
...org/springframework/boot/loader/jar/JarURLConnection.java
+5
-1
StringSequence.java
...a/org/springframework/boot/loader/jar/StringSequence.java
+13
-2
JarURLConnectionTests.java
...pringframework/boot/loader/jar/JarURLConnectionTests.java
+11
-0
StringSequenceTests.java
.../springframework/boot/loader/jar/StringSequenceTests.java
+42
-0
No files found.
spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java
View file @
cf27917e
...
...
@@ -255,6 +255,10 @@ final class JarURLConnection extends java.net.JarURLConnection {
static
JarURLConnection
get
(
URL
url
,
JarFile
jarFile
)
throws
IOException
{
StringSequence
spec
=
new
StringSequence
(
url
.
getFile
());
int
index
=
indexOfRootSpec
(
spec
,
jarFile
.
getPathFromRoot
());
if
(
index
==
-
1
)
{
return
(
Boolean
.
TRUE
.
equals
(
useFastExceptions
.
get
())
?
NOT_FOUND_CONNECTION
:
new
JarURLConnection
(
url
,
null
,
EMPTY_JAR_ENTRY_NAME
));
}
int
separator
;
while
((
separator
=
spec
.
indexOf
(
SEPARATOR
,
index
))
>
0
)
{
JarEntryName
entryName
=
JarEntryName
.
get
(
spec
.
subSequence
(
index
,
separator
));
...
...
@@ -275,7 +279,7 @@ final class JarURLConnection extends java.net.JarURLConnection {
private
static
int
indexOfRootSpec
(
StringSequence
file
,
String
pathFromRoot
)
{
int
separatorIndex
=
file
.
indexOf
(
SEPARATOR
);
if
(
separatorIndex
<
0
)
{
if
(
separatorIndex
<
0
||
!
file
.
startsWith
(
pathFromRoot
,
separatorIndex
)
)
{
return
-
1
;
}
return
separatorIndex
+
SEPARATOR
.
length
()
+
pathFromRoot
.
length
();
...
...
spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/StringSequence.java
View file @
cf27917e
...
...
@@ -95,6 +95,17 @@ final class StringSequence implements CharSequence {
return
this
.
source
.
indexOf
(
str
,
this
.
start
+
fromIndex
)
-
this
.
start
;
}
public
boolean
startsWith
(
CharSequence
prefix
)
{
return
startsWith
(
prefix
,
0
);
}
public
boolean
startsWith
(
CharSequence
prefix
,
int
toffset
)
{
if
(
length
()
-
prefix
.
length
()
-
toffset
<
0
)
{
return
false
;
}
return
subSequence
(
toffset
,
toffset
+
prefix
.
length
()).
equals
(
prefix
);
}
@Override
public
String
toString
()
{
return
this
.
source
.
substring
(
this
.
start
,
this
.
end
);
...
...
@@ -117,10 +128,10 @@ final class StringSequence implements CharSequence {
if
(
this
==
obj
)
{
return
true
;
}
if
(
obj
==
null
||
getClass
()
!=
obj
.
getClass
(
))
{
if
(
obj
==
null
||
!
CharSequence
.
class
.
isInstance
(
obj
))
{
return
false
;
}
StringSequence
other
=
(
String
Sequence
)
obj
;
CharSequence
other
=
(
Char
Sequence
)
obj
;
int
n
=
length
();
if
(
n
==
other
.
length
())
{
int
i
=
0
;
...
...
spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarURLConnectionTests.java
View file @
cf27917e
...
...
@@ -18,6 +18,7 @@ package org.springframework.boot.loader.jar;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.net.URL
;
import
org.junit.Before
;
...
...
@@ -149,6 +150,16 @@ public class JarURLConnectionTests {
.
hasSameContentAs
(
new
ByteArrayInputStream
(
new
byte
[]
{
3
}));
}
@Test
public
void
connectionToEntryUsingWrongAbsoluteUrlForEntryFromNestedJarFile
()
throws
Exception
{
URL
url
=
new
URL
(
"jar:file:"
+
getAbsolutePath
()
+
"!/w.jar!/3.dat"
);
JarFile
nested
=
this
.
jarFile
.
getNestedJarFile
(
this
.
jarFile
.
getEntry
(
"nested.jar"
));
this
.
thrown
.
expect
(
FileNotFoundException
.
class
);
JarURLConnection
.
get
(
url
,
nested
).
getInputStream
();
}
@Test
public
void
getContentLengthReturnsLengthOfUnderlyingEntry
()
throws
Exception
{
URL
url
=
new
URL
(
new
URL
(
"jar"
,
null
,
-
1
,
...
...
spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/StringSequenceTests.java
View file @
cf27917e
...
...
@@ -167,4 +167,46 @@ public class StringSequenceTests {
assertThat
(
a
).
isEqualTo
(
b
).
isNotEqualTo
(
c
);
}
@Test
public
void
startsWithWhenExactMatch
()
{
assertThat
(
new
StringSequence
(
"abc"
).
startsWith
(
"abc"
)).
isTrue
();
}
@Test
public
void
startsWithWhenLongerAndStartsWith
()
{
assertThat
(
new
StringSequence
(
"abcd"
).
startsWith
(
"abc"
)).
isTrue
();
}
@Test
public
void
startsWithWhenLongerAndDoesNotStartWith
()
{
assertThat
(
new
StringSequence
(
"abcd"
).
startsWith
(
"abx"
)).
isFalse
();
}
@Test
public
void
startsWithWhenShorterAndDoesNotStartWith
()
{
assertThat
(
new
StringSequence
(
"ab"
).
startsWith
(
"abc"
)).
isFalse
();
assertThat
(
new
StringSequence
(
"ab"
).
startsWith
(
"c"
)).
isFalse
();
}
@Test
public
void
startsWithOffsetWhenExactMatch
()
{
assertThat
(
new
StringSequence
(
"xabc"
).
startsWith
(
"abc"
,
1
)).
isTrue
();
}
@Test
public
void
startsWithOffsetWhenLongerAndStartsWith
()
{
assertThat
(
new
StringSequence
(
"xabcd"
).
startsWith
(
"abc"
,
1
)).
isTrue
();
}
@Test
public
void
startsWithOffsetWhenLongerAndDoesNotStartWith
()
{
assertThat
(
new
StringSequence
(
"xabcd"
).
startsWith
(
"abx"
,
1
)).
isFalse
();
}
@Test
public
void
startsWithOffsetWhenShorterAndDoesNotStartWith
()
{
assertThat
(
new
StringSequence
(
"xab"
).
startsWith
(
"abc"
,
1
)).
isFalse
();
assertThat
(
new
StringSequence
(
"xab"
).
startsWith
(
"c"
,
1
)).
isFalse
();
}
}
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