mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-09-23 06:05:46 +00:00
Merge pull request #122 from nlevitt/form-login-checked-boxes
only submit checkbox and radio button form fields if they are on by d…
This commit is contained in:
@@ -152,7 +152,14 @@ public class ExtractorHTMLForms extends Extractor {
|
||||
String type = findAttributeValueGroup("(?i)^[^>]*\\stype\\s*=\\s*([^>\\s]+)[^>]*>",1,input);
|
||||
String name = findAttributeValueGroup("(?i)^[^>]*\\sname\\s*=\\s*([^>\\s]+)[^>]*>",1,input);
|
||||
String value = findAttributeValueGroup("(?i)^[^>]*\\svalue\\s*=\\s*([^>\\s]+)[^>]*>",1,input);
|
||||
form.addField(type,name,value);
|
||||
Matcher m = TextUtils.getMatcher("(?i)^[^>]*\\schecked\\s*[^>]*>", input);
|
||||
boolean checked = false;
|
||||
try {
|
||||
checked = m.find();
|
||||
} finally {
|
||||
TextUtils.recycleMatcher(m);
|
||||
}
|
||||
form.addField(type, name, value, checked);
|
||||
}
|
||||
if (form.seemsLoginForm() || getExtractAllForms()) {
|
||||
curi.getDataList(A_HTML_FORM_OBJECTS).add(form);
|
||||
|
||||
@@ -37,9 +37,14 @@ public class HTMLForm {
|
||||
public String type;
|
||||
public String name;
|
||||
public String value;
|
||||
public boolean checked = false;
|
||||
@Override
|
||||
public String toString() {
|
||||
return type+" "+name+" "+value;
|
||||
String str = "input[@type='" + type+"'][@name='" + name + "'][@value='" + value + "']";
|
||||
if (checked) {
|
||||
str = str + "[@checked]";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,8 +61,9 @@ public class HTMLForm {
|
||||
* @param type
|
||||
* @param name
|
||||
* @param value
|
||||
* @param checked true if "checked" attribute is present (for radio buttons and checkboxes)
|
||||
*/
|
||||
public void addField(String type, String name, String value) {
|
||||
public void addField(String type, String name, String value, boolean checked) {
|
||||
FormInput input = new FormInput();
|
||||
input.type = type;
|
||||
// default input type is text per html standard
|
||||
@@ -72,6 +78,18 @@ public class HTMLForm {
|
||||
} else if ("password".equalsIgnoreCase(type)) {
|
||||
candidatePasswordInputs.add(input);
|
||||
}
|
||||
input.checked = checked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a discovered INPUT, tracking it as potential
|
||||
* username/password receiver.
|
||||
* @param type
|
||||
* @param name
|
||||
* @param value
|
||||
*/
|
||||
public void addField(String type, String name, String value) {
|
||||
addField(type, name, value, false);
|
||||
}
|
||||
|
||||
public void setMethod(String method) {
|
||||
@@ -131,8 +149,12 @@ public class HTMLForm {
|
||||
nameVals.add(TextUtils.urlEscape(input.name) + "=" + TextUtils.urlEscape(username));
|
||||
} else if(input == candidatePasswordInputs.get(0)) {
|
||||
nameVals.add(TextUtils.urlEscape(input.name) + "=" + TextUtils.urlEscape(password));
|
||||
} else if (StringUtils.isNotEmpty(input.name) && StringUtils.isNotEmpty(input.value)) {
|
||||
nameVals.add(TextUtils.urlEscape(input.name) + "=" + TextUtils.urlEscape(input.value));
|
||||
} else if (StringUtils.isNotEmpty(input.name)
|
||||
&& StringUtils.isNotEmpty(input.value)
|
||||
&& (!"radio".equalsIgnoreCase(input.type)
|
||||
&& !"checkbox".equals(input.type) || input.checked)) {
|
||||
nameVals.add(TextUtils.urlEscape(input.name) + "="
|
||||
+ TextUtils.urlEscape(input.value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user