-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLCharDetectTest.java
More file actions
67 lines (53 loc) · 1.71 KB
/
Copy pathSQLCharDetectTest.java
File metadata and controls
67 lines (53 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.hsbc.carm.common.data;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.Test;
import com.hsbc.carm.common.util.Escape;
public class SQLCharDetectTest {
String pattern1 = "\'";
final Pattern SQLPATTERN = Pattern.compile(pattern1);
String pattern2="'(''|[^'])*'";
final Pattern SQLPATTERN2=Pattern.compile(pattern2);
@Test
public void isSQL(){
String str="'KAYRIS CHILDRENS' SHOES";
String search="";
boolean checkStr=checkString(str);
System.out.println("first string "+str);
if(checkStr){
System.out.println("SQL DETECTED AND WILL BE ESCAPED");
str = Escape.forSQL(str);
}
else{
System.out.println("NOT AN SQL");
str = Escape.forSQLForSpecialName(str);
}
System.out.println("final string "+str);
}
public Boolean checkString(String str){
return patternMatch(str, SQLPATTERN2);
}
public Boolean patternMatch(final String str, final Pattern p){
java.util.regex.Matcher m=p.matcher(str);
return m.matches();
}
public String patternFind(final String str, final Pattern p){
java.util.regex.Matcher m=p.matcher(str);
StringBuffer sb=new StringBuffer();
while(m.find()){
sb.append(m.group());
//System.out.format("String %s found at %d to %d.%n ", m.group(),m.start(),m.end());
}
return sb.toString();
}
public void bla(){
String search="";
String singleQuote="'";
if(search.indexOf(singleQuote)>0 && search.indexOf(singleQuote) < search.length()){
System.out.println("Search customer name waived from SQL filtering");
}
else{
search = Escape.forSQL(search);
}
}
}