Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
finance-manage
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
finance-oa
finance-manage
Commits
bd09e5b1
Commit
bd09e5b1
authored
Nov 01, 2021
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复字符串无法被反转义问题
parent
181f62c1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
11 deletions
+23
-11
ruoyi-common/src/main/java/com/ruoyi/common/utils/html/EscapeUtil.java
...src/main/java/com/ruoyi/common/utils/html/EscapeUtil.java
+23
-11
No files found.
ruoyi-common/src/main/java/com/ruoyi/common/utils/html/EscapeUtil.java
View file @
bd09e5b1
...
...
@@ -69,26 +69,37 @@ public class EscapeUtil
*/
private
static
String
encode
(
String
text
)
{
int
len
;
if
((
text
==
null
)
||
((
len
=
text
.
length
())
==
0
))
if
(
StringUtils
.
isEmpty
(
text
))
{
return
StringUtils
.
EMPTY
;
}
StringBuilder
buffer
=
new
StringBuilder
(
len
+
(
len
>>
2
));
final
StringBuilder
tmp
=
new
StringBuilder
(
text
.
length
()
*
6
);
char
c
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
for
(
int
i
=
0
;
i
<
text
.
length
()
;
i
++)
{
c
=
text
.
charAt
(
i
);
if
(
c
<
64
)
if
(
c
<
256
)
{
tmp
.
append
(
"%"
);
if
(
c
<
16
)
{
buffer
.
append
(
TEXT
[
c
]);
tmp
.
append
(
"0"
);
}
tmp
.
append
(
Integer
.
toString
(
c
,
16
));
}
else
{
buffer
.
append
(
c
);
tmp
.
append
(
"%u"
);
if
(
c
<=
0xfff
)
{
// issue#I49JU8@Gitee
tmp
.
append
(
"0"
);
}
tmp
.
append
(
Integer
.
toString
(
c
,
16
));
}
}
return
buffer
.
toString
();
return
tmp
.
toString
();
}
/**
...
...
@@ -145,11 +156,12 @@ public class EscapeUtil
public
static
void
main
(
String
[]
args
)
{
String
html
=
"<script>alert(1);</script>"
;
String
escape
=
EscapeUtil
.
escape
(
html
);
// String html = "<scr<script>ipt>alert(\"XSS\")</scr<script>ipt>";
// String html = "<123";
// String html = "123>";
System
.
out
.
println
(
EscapeUtil
.
clean
(
html
));
System
.
out
.
println
(
EscapeUtil
.
escape
(
html
)
);
System
.
out
.
println
(
EscapeUtil
.
unescape
(
html
));
System
.
out
.
println
(
"clean: "
+
EscapeUtil
.
clean
(
html
));
System
.
out
.
println
(
"escape: "
+
escape
);
System
.
out
.
println
(
"unescape: "
+
EscapeUtil
.
unescape
(
escape
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment