File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed
main/java/us/codecraft/webmagic/utils
test/java/us/codecraft/webmagic/utils Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,10 @@ public static List<String> convertToUrls(Collection<Request> requests) {
116116 private static final Pattern patternForCharset = Pattern .compile ("charset\\ s*=\\ s*['\" ]*([^\\ s;'\" ]*)" , Pattern .CASE_INSENSITIVE );
117117
118118 public static String getCharset (String contentType ) {
119+ if (contentType == null ) {
120+ return null ;
121+ }
122+
119123 Matcher matcher = patternForCharset .matcher (contentType );
120124 if (matcher .find ()) {
121125 String charset = matcher .group (1 );
Original file line number Diff line number Diff line change 11package us .codecraft .webmagic .utils ;
22
3+ import static org .junit .Assert .assertNull ;
4+
35import org .junit .Assert ;
46import org .junit .Test ;
57
@@ -43,5 +45,9 @@ public void testGetDomain(){
4345 Assert .assertEquals ("www.dianping.com" ,UrlUtils .getDomain (url ));
4446 }
4547
48+ @ Test
49+ public void testGetCharset () {
50+ assertNull (UrlUtils .getCharset (null ));
51+ }
4652
4753}
You can’t perform that action at this time.
0 commit comments