From 868942e202aeb967b8ce47b38cc2433a636a128d Mon Sep 17 00:00:00 2001 From: phanes <5411232+phanes@user.noreply.gitee.com> Date: 星期日, 16 一月 2022 17:46:24 +0800 Subject: [PATCH] update 格式化代码结构 统一编码格式 --- ruoyi-common/src/main/java/com/ruoyi/common/filter/XssFilter.java | 33 +++++++++++---------------------- 1 files changed, 11 insertions(+), 22 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/filter/XssFilter.java b/ruoyi-common/src/main/java/com/ruoyi/common/filter/XssFilter.java index 869aef5..72a8f27 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/filter/XssFilter.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/filter/XssFilter.java @@ -1,6 +1,6 @@ package com.ruoyi.common.filter; -import cn.hutool.core.util.StrUtil; +import com.ruoyi.common.utils.StringUtils; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; @@ -8,30 +8,24 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * 闃叉XSS鏀诲嚮鐨勮繃婊ゅ櫒 * * @author ruoyi */ -public class XssFilter implements Filter -{ +public class XssFilter implements Filter { /** * 鎺掗櫎閾炬帴 */ public List<String> excludes = new ArrayList<>(); @Override - public void init(FilterConfig filterConfig) throws ServletException - { + public void init(FilterConfig filterConfig) throws ServletException { String tempExcludes = filterConfig.getInitParameter("excludes"); - if (StrUtil.isNotEmpty(tempExcludes)) - { + if (StringUtils.isNotEmpty(tempExcludes)) { String[] url = tempExcludes.split(","); - for (int i = 0; url != null && i < url.length; i++) - { + for (int i = 0; url != null && i < url.length; i++) { excludes.add(url[i]); } } @@ -39,12 +33,10 @@ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws IOException, ServletException - { + throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; - if (handleExcludeURL(req, resp)) - { + if (handleExcludeURL(req, resp)) { chain.doFilter(request, response); return; } @@ -52,21 +44,18 @@ chain.doFilter(xssRequest, response); } - private boolean handleExcludeURL(HttpServletRequest request, HttpServletResponse response) - { + private boolean handleExcludeURL(HttpServletRequest request, HttpServletResponse response) { String url = request.getServletPath(); String method = request.getMethod(); // GET DELETE 涓嶈繃婊� - if (method == null || method.matches("GET") || method.matches("DELETE")) - { + if (method == null || method.matches("GET") || method.matches("DELETE")) { return true; } - return StrUtil.matches(url, excludes); + return StringUtils.matches(url, excludes); } @Override - public void destroy() - { + public void destroy() { } } -- Gitblit v1.9.3