Skip to content

Commit

Permalink
fix html
Browse files Browse the repository at this point in the history
  • Loading branch information
looly committed Oct 23, 2018
1 parent 0aede27 commit 8d91340
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
## 4.1.19

### 新特性
* 【extra】 Ftp增加setMode方法(issue#INPMZ@Gitee)

### Bug修复
* 【core】 修复ImageUtil文件流未关闭问题(感谢@【西安】追寻)
* 【core】 修复ZipUtil中gzip和zlib方法未调用finish导致的问题(issue#INSXF@Gitee)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cn.hutool.cron.demo;

import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.cron.CronUtil;

/**
Expand All @@ -10,8 +9,6 @@ public class JobMainTest {

public static void main(String[] args) {
CronUtil.setMatchSecond(true);
CronUtil.start(true);

ThreadUtil.sleep(Integer.MAX_VALUE);
CronUtil.start(false);
}
}
3 changes: 2 additions & 1 deletion hutool-cron/src/test/java/cn/hutool/cron/demo/TestJob.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.hutool.cron.demo;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.IdUtil;
Expand All @@ -19,7 +20,7 @@ public class TestJob {
*/
public void doTest() {
// String name = Thread.currentThread().getName();
Console.log("Test Job {} running...", jobId);
Console.log("Test Job {} running... at {}", jobId, DateUtil.now());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion hutool-cron/src/test/resources/config/cron.setting
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
# TestJob.doTest = */1 * * * * *
# 5位表达式在分匹配模式下可用,此处表示每分钟执行一次
# 如果此时为秒匹配模式,则秒部分为固定数字(此秒取决于加入表达式当前时间的秒数)
TestJob.doTest = */2 * * * * *
TestJob.doTest = 0/30 * 8-18 * * ?
TestJob2.doTest = */3 * * * * *
47 changes: 33 additions & 14 deletions hutool-extra/src/main/java/cn/hutool/extra/ftp/Ftp.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
* @since 4.1.8
*/
public class Ftp extends AbstractFtp {

/** 默认端口 */
public static final int DEFAULT_PORT = 21;

private FTPClient client;
private Charset charset;

/**
* 构造,匿名登录
*
Expand All @@ -41,7 +41,7 @@ public class Ftp extends AbstractFtp {
public Ftp(String host) {
this(host, DEFAULT_PORT);
}

/**
* 构造,匿名登录
*
Expand All @@ -51,7 +51,7 @@ public Ftp(String host) {
public Ftp(String host, int port) {
this(host, port, "anonymous", "");
}

/**
* 构造
*
Expand Down Expand Up @@ -111,6 +111,25 @@ public Ftp init(String host, int port, String user, String password) {
return this;
}

/**
* 设置FTP连接模式,可选主动和被动模式
*
* @param mode 模式枚举
* @return this
* @since 4.1.19
*/
public Ftp setMode(FtpMode mode) {
switch (mode) {
case Active:
this.client.enterLocalActiveMode();
break;
case Passive:
this.client.enterLocalPassiveMode();
break;
}
return this;
}

/**
* 改变目录
*
Expand All @@ -127,7 +146,7 @@ public boolean cd(String directory) {
}
return flag;
}

/**
* 远程当前目录
*
Expand All @@ -142,7 +161,7 @@ public String pwd() {
throw new FtpException(e);
}
}

@Override
public List<String> ls(String path) {
try {
Expand All @@ -151,7 +170,7 @@ public List<String> ls(String path) {
throw new FtpException(e);
}
}

@Override
public boolean mkdir(String dir) {
boolean flag = true;
Expand All @@ -162,7 +181,7 @@ public boolean mkdir(String dir) {
}
return flag;
}

/**
* 判断ftp服务器文件是否存在
*
Expand Down Expand Up @@ -211,17 +230,17 @@ public boolean delDir(String dirPath) {
for (FTPFile ftpFile : dirs) {
name = ftpFile.getName();
childPath = StrUtil.format("{}/{}", dirPath, name);
if(ftpFile.isDirectory()) {
//上级和本级目录除外
if (ftpFile.isDirectory()) {
// 上级和本级目录除外
if (false == name.equals(".") && false == name.equals("..")) {
delDir(childPath);
}
}else {
} else {
delFile(childPath);
}
}
//删除空目录

// 删除空目录
try {
return this.client.removeDirectory(dirPath);
} catch (IOException e) {
Expand Down Expand Up @@ -280,7 +299,7 @@ public boolean upload(String path, String fileName, InputStream fileStream) {
throw new FtpException(e);
}
}

/**
* 下载文件
*
Expand Down
17 changes: 17 additions & 0 deletions hutool-extra/src/main/java/cn/hutool/extra/ftp/FtpMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cn.hutool.extra.ftp;

/**
* FTP连接模式
*
* <p>
* 见:https://www.cnblogs.com/huhaoshida/p/5412615.html
*
* @author looly
* @since 4.1.19
*/
public enum FtpMode {
/** 主动模式 */
Active,
/** 被动模式 */
Passive;
}
3 changes: 2 additions & 1 deletion hutool-extra/src/main/java/cn/hutool/extra/ssh/JschUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class JschUtil {
public static int generateLocalPort() {
return portGenerater.generate();
}

/**
* 获得一个SSH跳板机会话,重用已经使用的会话
*
Expand Down Expand Up @@ -72,6 +72,7 @@ public static Session openSession(String sshHost, int sshPort, String sshUser, S
try {
session = new JSch().getSession(sshUser, sshHost, sshPort);
session.setPassword(sshPass);
//设置第一次登陆的时候提示,可选值:(ask | yes | no)
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
} catch (JSchException e) {
Expand Down
7 changes: 4 additions & 3 deletions hutool-http/src/main/java/cn/hutool/http/HTMLFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import cn.hutool.log.StaticLog;

/**
*
* HTML filtering utility for protecting against XSS (Cross Site Scripting).
Expand Down Expand Up @@ -181,7 +182,7 @@ private void reset() {

private void debug(final String msg) {
if (vDebug) {
Logger.getAnonymousLogger().info(msg);
StaticLog.debug(msg);
}
}

Expand Down Expand Up @@ -331,7 +332,7 @@ private String processTag(final String s) {
if (m.find()) {
final String name = m.group(1).toLowerCase();
if (allowed(name)) {
if (!inArray(name, vSelfClosingTags)) {
if (false == inArray(name, vSelfClosingTags)) {
if (vTagCounts.containsKey(name)) {
vTagCounts.put(name, vTagCounts.get(name) - 1);
return "</" + name + ">";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,11 @@ public void escapeTest() {
String restoreEscaped = HtmlUtil.unescape(escape);
Assert.assertEquals(html, restoreEscaped);
}

@Test
public void filterTest() {
String html = "<alert></alert>";
String filter = HtmlUtil.filter(html);
Assert.assertEquals("", filter);
}
}

0 comments on commit 8d91340

Please sign in to comment.