-
Notifications
You must be signed in to change notification settings - Fork 813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WW-5352 Refactor ParametersInterceptor #831
Conversation
9afea18
to
5c7a6bc
Compare
5c7a6bc
to
8a245e8
Compare
@@ -32,37 +32,37 @@ public interface AcceptedPatternsChecker { | |||
* @param value to check | |||
* @return object containing result of matched pattern and pattern itself | |||
*/ | |||
public IsAccepted isAccepted(String value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant in interfaces
@@ -58,7 +58,7 @@ public String getName() { | |||
@Override | |||
public String getValue() { | |||
String[] values = toStringArray(); | |||
return (values != null && values.length > 0) ? values[0] : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#toStringArray
never returns a null value
@@ -132,138 +133,149 @@ static private int countOGNLCharacters(String s) { | |||
@Override | |||
public String doIntercept(ActionInvocation invocation) throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used early returns to reduce nesting and improve readability
* <p> | ||
* In this class this is a no-op, since the parameters were fetched from the same location. | ||
* In subclasses both retrieveParameters() and addParametersToContext() should be overridden. | ||
* </p> | ||
*/ | ||
protected void addParametersToContext(ActionContext ac, Map<String, ?> newParams) { | ||
} | ||
|
||
protected void setParameters(final Object action, ValueStack stack, HttpParameters parameters) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted a bunch of helper methods to make this method much more readable
boolean acceptableParamValue = (parameterValueAware == null || parameterValueAware.acceptableParameterValue(param.getValue())); | ||
if (hasParamValuesToExclude() || hasParamValuesToAccept()) { | ||
// Additional validations to process | ||
acceptableParamValue &= acceptableValue(param.getName(), param.getValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&=
doesn't short-circuit
@@ -338,18 +344,17 @@ protected boolean acceptableName(String name) { | |||
return false; | |||
} | |||
boolean accepted = isWithinLengthLimit(name) && !isExcluded(name) && isAccepted(name); | |||
if (devMode && accepted) { // notify only when in devMode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaned out comments for behaviours which are fairly obvious from code
core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java
Outdated
Show resolved
Hide resolved
Quality Gate failedFailed conditions 10 Security Hotspots See analysis details on SonarCloud Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
@lukaszlenart Any idea how to configure a second base branch for SonarCloud dedicated to 7.x so we don't get wonky results? |
WW-5352
General clean up in preparation for #832