From 469b37e1c10108f4133d64b91664fa9b702b2da2 Mon Sep 17 00:00:00 2001 From: kevodwyer Date: Wed, 25 Jan 2023 10:32:06 +0000 Subject: [PATCH] remove double encoding. issue: 111 --- src/main/java/io/ipfs/api/NamedStreamable.java | 6 +----- src/test/java/io/ipfs/api/SimpleAddTest.java | 9 +++++++++ .../resources/folder/\344\275\240\345\245\275.html" | 10 ++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 "src/test/resources/folder/\344\275\240\345\245\275.html" diff --git a/src/main/java/io/ipfs/api/NamedStreamable.java b/src/main/java/io/ipfs/api/NamedStreamable.java index 14b184e8..642d9ba3 100644 --- a/src/main/java/io/ipfs/api/NamedStreamable.java +++ b/src/main/java/io/ipfs/api/NamedStreamable.java @@ -52,11 +52,7 @@ public List getChildren() { } public Optional getName() { - try { - return Optional.of(URLEncoder.encode(source.getName(), "UTF-8")); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } + return Optional.of(source.getName()); } } diff --git a/src/test/java/io/ipfs/api/SimpleAddTest.java b/src/test/java/io/ipfs/api/SimpleAddTest.java index ae1aef56..0d7bb30c 100644 --- a/src/test/java/io/ipfs/api/SimpleAddTest.java +++ b/src/test/java/io/ipfs/api/SimpleAddTest.java @@ -56,6 +56,15 @@ public void testAddArgs() throws Exception { Assert.assertEquals(1, tree.size()); Assert.assertEquals("index.html", tree.get(0).name.get()); } + @Test + public void testFilenameEncoding() throws Exception { + Path path = Paths.get("src/test/resources/folder/你好.html"); + NamedStreamable file = new FileWrapper(path.toFile()); + List tree = ipfs.add(file); + + Assert.assertEquals(1, tree.size()); + Assert.assertEquals("你好.html", tree.get(0).name.get()); + } @Test public void testSingleWrapped() throws Exception { diff --git "a/src/test/resources/folder/\344\275\240\345\245\275.html" "b/src/test/resources/folder/\344\275\240\345\245\275.html" new file mode 100644 index 00000000..b46d9d4d --- /dev/null +++ "b/src/test/resources/folder/\344\275\240\345\245\275.html" @@ -0,0 +1,10 @@ + + + + Blank page + + + +

blank

+ +