This repository was archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 367
This repository was archived by the owner on Jan 19, 2022. It is now read-only.
SimpleStorageResource does not escape special characters in getURI #483
Copy link
Copy link
Closed
Labels
component: s3S3 integration related issueS3 integration related issuehelp wantedtype: bugA general bugA general bug
Milestone
Description
In spring-cloud-aws-core
v2.1.2, the SimpleStorageResource
does not properly escape special characters when generating URLs or URIs
The following test fails,
@Test
public void getUri_escapes_characters() throws Exception {
AmazonS3 s3 = mock(AmazonS3.class);
when(s3.getRegion()).thenReturn(Region.US_West_2);
SimpleStorageResource resource =
new SimpleStorageResource(s3,
"bucketName",
"some/[objectName]",
new SyncTaskExecutor());
assertThat(resource.getURI())
.isEqualTo(new URI("https://s3.us-west-2.amazonaws.com/bucketName/some/%5BobjectName%5D"));
}
It throws,
org.springframework.core.NestedIOException: Invalid URI [https://s3.us-west-2.amazonaws.com/bucketName/some/[objectName]]; nested exception is java.net.URISyntaxException: Illegal character in path at index 51: https://s3.us-west-2.amazonaws.com/bucketName/some/[objectName]
at org.springframework.core.io.AbstractResource.getURI(AbstractResource.java:114)
at org.springframework.cloud.aws.core.io.s3.SimpleStorageResourceTest.getUri_escapes_characters(SimpleStorageResourceTest.java:313)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.net.URISyntaxException: Illegal character in path at index 51: https://s3.us-west-2.amazonaws.com/bucketName/some/[objectName]
at java.net.URI$Parser.fail(URI.java:2848)
at java.net.URI$Parser.checkChars(URI.java:3021)
at java.net.URI$Parser.parseHierarchical(URI.java:3105)
at java.net.URI$Parser.parse(URI.java:3053)
at java.net.URI.<init>(URI.java:588)
at org.springframework.util.ResourceUtils.toURI(ResourceUtils.java:381)
at org.springframework.util.ResourceUtils.toURI(ResourceUtils.java:370)
at org.springframework.core.io.AbstractResource.getURI(AbstractResource.java:111)
... 25 more
Metadata
Metadata
Assignees
Labels
component: s3S3 integration related issueS3 integration related issuehelp wantedtype: bugA general bugA general bug