Skip to content

Commit

Permalink
Merge pull request #97 from LiuXing-R/useless-exception
Browse files Browse the repository at this point in the history
refactor: partially invalid exception thrown
  • Loading branch information
davewichers authored Aug 9, 2021
2 parents 5f8c9ef + 5e57384 commit f109ea4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
13 changes: 4 additions & 9 deletions src/main/java/org/owasp/validator/html/AntiSamy.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ public AntiSamy(Policy policy) {
* @throws PolicyException When there is a problem reading the policy file.
*/
public CleanResults scan(String taintedHTML) throws ScanException, PolicyException {

if (policy == null) {
throw new PolicyException("No policy loaded");
}

return this.scan(taintedHTML, this.policy, SAX);
}

Expand All @@ -88,9 +83,6 @@ public CleanResults scan(String taintedHTML) throws ScanException, PolicyExcepti
*/
public CleanResults scan(String taintedHTML, int scanType) throws ScanException, PolicyException {

if (policy == null) {
throw new PolicyException("No policy loaded");
}
return this.scan(taintedHTML, this.policy, scanType);
}

Expand All @@ -106,7 +98,7 @@ public CleanResults scan(String taintedHTML, int scanType) throws ScanException,
* @throws PolicyException When there is a problem reading the policy file.
*/
public CleanResults scan(String taintedHTML, Policy policy) throws ScanException, PolicyException {
return new AntiSamyDOMScanner(policy).scan(taintedHTML);
return this.scan(taintedHTML, policy, DOM);
}

/**
Expand All @@ -122,6 +114,9 @@ public CleanResults scan(String taintedHTML, Policy policy) throws ScanException
* @throws PolicyException When there is a problem reading the policy file.
*/
public CleanResults scan(String taintedHTML, Policy policy, int scanType) throws ScanException, PolicyException {
if (policy == null) {
throw new PolicyException("No policy loaded");
}

if (scanType == DOM) {
return new AntiSamyDOMScanner(policy).scan(taintedHTML);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/owasp/validator/html/InternalPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class InternalPolicy extends Policy {
private final boolean allowDynamicAttributes;


protected InternalPolicy(ParseContext parseContext) throws PolicyException {
protected InternalPolicy(ParseContext parseContext) {
super(parseContext);
this.maxInputSize = determineMaxInputSize();
this.isNofollowAnchors = isTrue(Policy.ANCHORS_NOFOLLOW);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/owasp/validator/html/Policy.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public static Policy getInstance(URL url) throws PolicyException {
return new InternalPolicy(getParseContext(getTopLevelElement(url), url));
}

protected Policy(ParseContext parseContext) throws PolicyException {
protected Policy(ParseContext parseContext) {
this.allowedEmptyTagsMatcher = new TagMatcher(parseContext.allowedEmptyTags);
this.requiresClosingTagsMatcher = new TagMatcher(parseContext.requireClosingTags);
this.commonRegularExpressions = Collections.unmodifiableMap(parseContext.commonRegularExpressions);
Expand Down Expand Up @@ -657,7 +657,7 @@ private static void parseDirectives(Element root, Map<String, String> directives
* @param allowedEmptyTags The tags that can be empty
*/
private static void parseAllowedEmptyTags(Element allowedEmptyTagsListNode,
List<String> allowedEmptyTags) throws PolicyException {
List<String> allowedEmptyTags) {
if (allowedEmptyTagsListNode != null) {
for (Element literalNode :
getGrandChildrenByTagName(allowedEmptyTagsListNode, "literal-list", "literal")) {
Expand All @@ -677,7 +677,7 @@ private static void parseAllowedEmptyTags(Element allowedEmptyTagsListNode,
* @param requireClosingTags The list of tags that require closing
*/
private static void parseRequireClosingTags(Element requireClosingTagsListNode,
List<String> requireClosingTags) throws PolicyException {
List<String> requireClosingTags) {
if (requireClosingTagsListNode != null) {
for (Element literalNode :
getGrandChildrenByTagName(requireClosingTagsListNode, "literal-list", "literal")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,11 +680,7 @@ private void removeNode(Node node) {
private boolean isAllowedEmptyTag(String tagName) {
return "head".equals(tagName ) || policy.getAllowedEmptyTags().matches(tagName);
}

public static void main(String[] args) throws PolicyException {
}



/**
* Used to promote the children of a parent to accomplish the "filterTag" action.
*
Expand Down

0 comments on commit f109ea4

Please sign in to comment.