File tree Expand file tree Collapse file tree 5 files changed +49
-12
lines changed Expand file tree Collapse file tree 5 files changed +49
-12
lines changed Original file line number Diff line number Diff line change 62
62
<antlr4 .version>4.13.0</antlr4 .version>
63
63
<jackson .databind.version>2.13.4.2</jackson .databind.version>
64
64
<jackson .version>2.13.2</jackson .version>
65
- <jsoup .version>1.15.3</jsoup .version>
66
65
<junit .version>4.13.1</junit .version>
67
66
68
67
<main .class />
101
100
<version >${jackson.version} </version >
102
101
</dependency >
103
102
104
-
105
- <dependency >
106
- <groupId >org.jsoup</groupId >
107
- <artifactId >jsoup</artifactId >
108
- <version >${jsoup.version} </version >
109
- </dependency >
110
-
111
103
<dependency >
112
104
<groupId >ua.co.k</groupId >
113
105
<artifactId >strftime4j</artifactId >
Original file line number Diff line number Diff line change @@ -493,4 +493,19 @@ public boolean isMap(Object value) {
493
493
public Map <String , Object > asMap (Object value ) {
494
494
return (Map <String , Object >)value ;
495
495
}
496
+
497
+ public static boolean isBlank (final String string ) {
498
+ if (string == null || string .length () == 0 )
499
+ return true ;
500
+
501
+ int l = string .length ();
502
+ for (int i = 0 ; i < l ; i ++) {
503
+ if (!isWhitespace (string .codePointAt (i )))
504
+ return false ;
505
+ }
506
+ return true ;
507
+ }
508
+ private static boolean isWhitespace (int c ){
509
+ return c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r' ;
510
+ }
496
511
}
Original file line number Diff line number Diff line change 1
1
package liqp .filters ;
2
2
3
3
import liqp .TemplateContext ;
4
- import org .jsoup .Jsoup ;
4
+
5
+ import java .util .regex .Pattern ;
5
6
6
7
public class Strip_HTML extends Filter {
7
8
9
+ // STRIP_HTML_BLOCKS = Regexp.union(
10
+ // /<script.*?<\/script>/m,
11
+ // /<!--.*?-->/m,
12
+ // /<style.*?<\/style>/m
13
+ // )
14
+ private static final Pattern STRIP_HTML_BLOCKS = Pattern .compile ("<script.*?</script>|<style.*?</style>|<!--.*?-->" , Pattern .MULTILINE );
15
+
16
+ // STRIP_HTML_TAGS = /<.*?>/m
17
+ private static final Pattern STRIP_HTML_TAGS = Pattern .compile ("<.*?>" , Pattern .MULTILINE );
18
+
8
19
/*
9
20
* strip_html(input)
10
21
*
@@ -14,7 +25,9 @@ public class Strip_HTML extends Filter {
14
25
public Object apply (Object value , TemplateContext context , Object ... params ) {
15
26
16
27
String html = super .asString (value , context );
28
+ html = STRIP_HTML_BLOCKS .matcher (html ).replaceAll ("" );
29
+ html = STRIP_HTML_TAGS .matcher (html ).replaceAll ("" );
17
30
18
- return Jsoup . parse ( html ). text () ;
31
+ return html ;
19
32
}
20
33
}
Original file line number Diff line number Diff line change 4
4
import liqp .TemplateContext ;
5
5
import liqp .TemplateParser ;
6
6
import liqp .exceptions .LiquidException ;
7
- import org .jsoup .internal .StringUtil ;
8
7
9
8
import java .math .BigDecimal ;
10
9
import java .util .ArrayList ;
11
10
import java .util .List ;
12
11
12
+ import static liqp .LValue .isBlank ;
13
+
13
14
public class OutputNode implements LNode {
14
15
15
16
private LNode expression ;
@@ -40,7 +41,7 @@ public Object render(TemplateContext context) {
40
41
}
41
42
if (context != null && context .getParser ().errorMode == TemplateParser .ErrorMode .WARN ) {
42
43
String localUnparsed = unparsed ;
43
- if (!StringUtil . isBlank (localUnparsed )) {
44
+ if (!isBlank (localUnparsed )) {
44
45
if (localUnparsed .length () > 30 ) {
45
46
localUnparsed = localUnparsed .substring (0 , 30 ) + "..." ;
46
47
}
Original file line number Diff line number Diff line change @@ -52,4 +52,20 @@ public void applyOriginalTest() {
52
52
assertThat (filter .apply ("<script type='text/javascript'>document.write('some stuff');</script>" , context ), is ((Object )"" ));
53
53
assertThat (filter .apply (null , context ), is ((Object )"" ));
54
54
}
55
+
56
+
57
+ @ Test
58
+ public void testIssue306 () {
59
+ // given
60
+ // {{ "<em>test</em>" | escape }} --> <em>test</em>
61
+ TemplateContext context = new TemplateContext ();
62
+ Filter filter = Filters .COMMON_FILTERS .get ("strip_html" );
63
+
64
+ // when
65
+ Object result = filter .apply ("<em>test</em>" , context );
66
+
67
+
68
+ // then
69
+ assertThat (result , is ("<em>test</em>" ));
70
+ }
55
71
}
You can’t perform that action at this time.
0 commit comments