Skip to content

Commit 38dc3c2

Browse files
committed
some websites put the charset encoding names between '' characters, so parse them as well.
1 parent afded43 commit 38dc3c2

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

cSploit/src/main/java/org/csploit/android/net/http/RequestParser.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,19 +505,21 @@ public static String getCharsetFromHeaders(String contentType){
505505
*/
506506
public static String getCharsetFromBody(String body) {
507507
if (body != null) {
508-
// match <body>, <body onLoad="">, etc...
509-
int headEnd = body.toLowerCase().indexOf("</head>");
508+
int headEnd = body.toLowerCase().trim().indexOf("</head>");
510509

511510
// return null if there's no head tags
512511
if (headEnd == -1)
513512
return null;
514513

515514
String body_head = body.toLowerCase().substring(0, headEnd);
516515

517-
Pattern p = Pattern.compile("charset=([\"a-z0-9A-Z-]+)");
516+
Pattern p = Pattern.compile("charset=([\"\'a-z0-9A-Z-]+)");
518517
Matcher m = p.matcher(body_head);
519-
if (m.find())
520-
return m.toMatchResult().group(1).replaceAll("\"", "");
518+
String str_match = "";
519+
if (m.find()) {
520+
str_match = m.toMatchResult().group(1);
521+
return str_match.replaceAll("[\"']", "");
522+
}
521523
}
522524

523525
return null;

0 commit comments

Comments
 (0)