Looly 5 years ago
parent
commit
67aa719b3c

+ 4 - 1
CHANGELOG.md

@@ -3,7 +3,7 @@
 
 
 -------------------------------------------------------------------------------------------------------------
 -------------------------------------------------------------------------------------------------------------
 
 
-# 5.4.4 (2020-09-22)
+# 5.4.4 (2020-09-23)
 
 
 ### 新特性
 ### 新特性
 * 【core   】     ServiceLoaderUtil改为使用contextClassLoader(pr#183@Gitee)
 * 【core   】     ServiceLoaderUtil改为使用contextClassLoader(pr#183@Gitee)
@@ -11,10 +11,13 @@
 * 【extra  】     FTP增加stat方法(issue#I1W346@Gitee)
 * 【extra  】     FTP增加stat方法(issue#I1W346@Gitee)
 * 【core   】     Convert.toNumber支持类似12.2F这种形式字符串转换(issue#I1VYLJ@Gitee)
 * 【core   】     Convert.toNumber支持类似12.2F这种形式字符串转换(issue#I1VYLJ@Gitee)
 * 【core   】     使用静态变量替换999等(issue#I1W8IB@Gitee)
 * 【core   】     使用静态变量替换999等(issue#I1W8IB@Gitee)
+* 【core   】     URLUtil自动trim(issue#I1W803@Gitee)
 
 
 ### Bug修复
 ### Bug修复
 * 【crypto 】     修复SM2验签后无法解密问题(issue#I1W0VP@Gitee)
 * 【crypto 】     修复SM2验签后无法解密问题(issue#I1W0VP@Gitee)
 * 【core   】     修复新建默认TreeSet没有默认比较器导致的问题(issue#1101@Github)
 * 【core   】     修复新建默认TreeSet没有默认比较器导致的问题(issue#1101@Github)
+* 【core   】     修复Linux下使用Windows路径分隔符导致的解压错误(issue#I1MW0E@Gitee)
+* 【core   】     修复Word07Writer写出map问题(issue#I1W49R@Gitee)
 
 
 -------------------------------------------------------------------------------------------------------------
 -------------------------------------------------------------------------------------------------------------
 
 

+ 3 - 9
hutool-core/src/main/java/cn/hutool/core/util/URLUtil.java

@@ -483,13 +483,7 @@ public class URLUtil {
 	 * @throws UtilException 包装URISyntaxException
 	 * @throws UtilException 包装URISyntaxException
 	 */
 	 */
 	public static String getPath(String uriStr) {
 	public static String getPath(String uriStr) {
-		URI uri;
-		try {
-			uri = new URI(uriStr);
-		} catch (URISyntaxException e) {
-			throw new UtilException(e);
-		}
-		return uri.getPath();
+		return toURI(uriStr).getPath();
 	}
 	}
 
 
 	/**
 	/**
@@ -509,7 +503,7 @@ public class URLUtil {
 		String path = null;
 		String path = null;
 		try {
 		try {
 			// URL对象的getPath方法对于包含中文或空格的问题
 			// URL对象的getPath方法对于包含中文或空格的问题
-			path = URLUtil.toURI(url).getPath();
+			path = toURI(url).getPath();
 		} catch (UtilException e) {
 		} catch (UtilException e) {
 			// ignore
 			// ignore
 		}
 		}
@@ -569,7 +563,7 @@ public class URLUtil {
 			location = encode(location);
 			location = encode(location);
 		}
 		}
 		try {
 		try {
-			return new URI(location);
+			return new URI(StrUtil.trim(location));
 		} catch (URISyntaxException e) {
 		} catch (URISyntaxException e) {
 			throw new UtilException(e);
 			throw new UtilException(e);
 		}
 		}

+ 2 - 0
hutool-core/src/main/java/cn/hutool/core/util/ZipUtil.java

@@ -1116,6 +1116,8 @@ public class ZipUtil {
 	 * @since 5.0.5
 	 * @since 5.0.5
 	 */
 	 */
 	private static File buildFile(File outFile, String fileName) {
 	private static File buildFile(File outFile, String fileName) {
+		// 替换Windows路径分隔符为Linux路径分隔符,便于统一处理
+		fileName = fileName.replace('\\', '/');
 		if (false == FileUtil.isWindows()
 		if (false == FileUtil.isWindows()
 				// 检查文件名中是否包含"/",不考虑以"/"结尾的情况
 				// 检查文件名中是否包含"/",不考虑以"/"结尾的情况
 				&& fileName.lastIndexOf(CharUtil.SLASH, fileName.length() - 2) > 0) {
 				&& fileName.lastIndexOf(CharUtil.SLASH, fileName.length() - 2) > 0) {

+ 7 - 0
hutool-core/src/test/java/cn/hutool/core/util/URLUtilTest.java

@@ -84,4 +84,11 @@ public class URLUtilTest {
 		String encode2 = URLUtil.encodeQuery(body);
 		String encode2 = URLUtil.encodeQuery(body);
 		Assert.assertEquals("366466+-+%E5%89%AF%E6%9C%AC.jpg", encode2);
 		Assert.assertEquals("366466+-+%E5%89%AF%E6%9C%AC.jpg", encode2);
 	}
 	}
+
+	@Test
+	public void getPathTest(){
+		String url = " http://www.aaa.bbb/search?scope=ccc&q=ddd";
+		String path = URLUtil.getPath(url);
+		Assert.assertEquals("/search", path);
+	}
 }
 }

+ 3 - 1
hutool-poi/src/main/java/cn/hutool/poi/word/TableUtil.java

@@ -71,7 +71,7 @@ public class TableUtil {
 			return;
 			return;
 		}
 		}
 		
 		
-		Map rowMap = null;
+		Map rowMap;
 		if(rowBean instanceof Map) {
 		if(rowBean instanceof Map) {
 			rowMap = (Map) rowBean;
 			rowMap = (Map) rowBean;
 		} else if (BeanUtil.isBean(rowBean.getClass())) {
 		} else if (BeanUtil.isBean(rowBean.getClass())) {
@@ -79,6 +79,7 @@ public class TableUtil {
 		} else {
 		} else {
 			// 其它转为字符串默认输出
 			// 其它转为字符串默认输出
 			writeRow(row, CollUtil.newArrayList(rowBean), isWriteKeyAsHead);
 			writeRow(row, CollUtil.newArrayList(rowBean), isWriteKeyAsHead);
+			return;
 		}
 		}
 		
 		
 		writeRow(row, rowMap, isWriteKeyAsHead);
 		writeRow(row, rowMap, isWriteKeyAsHead);
@@ -98,6 +99,7 @@ public class TableUtil {
 
 
 		if (isWriteKeyAsHead) {
 		if (isWriteKeyAsHead) {
 			writeRow(row, rowMap.keySet());
 			writeRow(row, rowMap.keySet());
+			row = row.getTable().createRow();
 		}
 		}
 		writeRow(row, rowMap.values());
 		writeRow(row, rowMap.values());
 	}
 	}

+ 17 - 0
hutool-poi/src/test/java/cn/hutool/poi/word/test/WordWriterTest.java

@@ -1,5 +1,6 @@
 package cn.hutool.poi.word.test;
 package cn.hutool.poi.word.test;
 
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.lang.Console;
 import cn.hutool.core.lang.Console;
 import cn.hutool.poi.word.Word07Writer;
 import cn.hutool.poi.word.Word07Writer;
@@ -8,6 +9,8 @@ import org.junit.Test;
 
 
 import java.awt.Font;
 import java.awt.Font;
 import java.io.File;
 import java.io.File;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 
 public class WordWriterTest {
 public class WordWriterTest {
 	
 	
@@ -32,4 +35,18 @@ public class WordWriterTest {
 		// 关闭
 		// 关闭
 		writer.close();
 		writer.close();
 	}
 	}
+
+	@Test
+	@Ignore
+	public void writeTableTest(){
+		final Word07Writer writer = new Word07Writer();
+		Map<String, Object> map = new LinkedHashMap<>();
+		map.put("姓名", "张三");
+		map.put("年龄", "23");
+		map.put("成绩", 88.32);
+		map.put("是否合格", true);
+
+		writer.addTable(CollUtil.newArrayList(map));
+		writer.flush(FileUtil.file("d:/test/test.docx"));
+	}
 }
 }