-
Notifications
You must be signed in to change notification settings - Fork 825
WW-4891 Debug tag should not display anything when not in dev mode #201
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
Conversation
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.
Left few comments, looks good to me but have some security related concerns
@@ -34,13 +34,12 @@ | |||
import org.apache.struts2.StrutsException; | |||
|
|||
@StrutsTag(name="debug", tldTagClass="org.apache.struts2.views.jsp.ui.DebugTag", | |||
description="Prints debugging information") | |||
description="Prints debugging information (Only if 'struts.devMode' enabled or disable tag is set 'false')") |
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.
I think this is a bit misleading, I would rephrase it:
(Only if 'struts.devMode' is enabled or a 'disabled' attribute is set 'false')
|
||
return result; | ||
protected boolean showDebug() { | ||
return (devMode || "false".equalsIgnoreCase(disabled)); |
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.
hm... the disabled
attribute can be controlled by client ($(".selector").attr("disabled", "false")
) but I do not see an option to do so on a page rendering on server side. Maybe some other pair of 👀 will catch this.
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.
There is also a property named disabled
in it's super class UIBean
which is different than html disabled
attribute.
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.
It's exactly the same, there is no another disabled
property in Debug
tag.
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.
$(".selector").attr("disabled", "false")
I meant your mentioned code above is at client side html and is not equal to that disabled
java property at server side which this PR uses.
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.
Yes but that property is settable via client -> <input disabled="false"/>
or ?disabled=true
- I'm not saying it's true in this case, that's why I asked for second pair of 👀
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.
That's why asked for second pair of 👀
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.
To be clear: disabled
is a user settable property, that's the purpose of this property, a pure client side thing. Right now it was used to control server side logic and I wonder if this is a good idea.
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.
Aha... yes I agree. However, debug.ftl
does not use it currently.
@HedjuHor , I found all references of UIBean.disabled
and saw it never used in java codes and always has been used inside ftl
(free marker template) files. As Łukasz correctly warned, if you look it's usages inside ftl
files, you'll see currently it's purpose is only to generate or not generate html disabled
attribute. So I also think it may not a good idea to use it here, in not it's business ;)
@HedjuHor , @lukaszlenart , what do you feel using it inside debug.ftl
instead as below:
Index: core/src/main/resources/template/simple/debug.ftl
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/main/resources/template/simple/debug.ftl (date 1515941681000)
+++ core/src/main/resources/template/simple/debug.ftl (revision )
@@ -18,6 +18,8 @@
* under the License.
*/
-->
+<#if parameters.disabled!false>
+<#else >
<script type="text/javascript">
<!--
function toggleDebug(debugId) {
@@ -86,3 +88,4 @@
</#list>
</table>
</div>
+</#if>
\ No newline at end of file
Index: core/src/main/java/org/apache/struts2/components/Debug.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/main/java/org/apache/struts2/components/Debug.java (date 1515941681000)
+++ core/src/main/java/org/apache/struts2/components/Debug.java (revision )
@@ -41,6 +41,7 @@
protected ReflectionProvider reflectionProvider;
+
public Debug(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
}
@@ -57,38 +58,31 @@
public boolean start(Writer writer) {
boolean result = super.start(writer);
- if (showDebug()) {
- ValueStack stack = getStack();
- Iterator iter = stack.getRoot().iterator();
- List stackValues = new ArrayList(stack.getRoot().size());
- while (iter.hasNext()) {
- Object o = iter.next();
- Map values;
- try {
- values = reflectionProvider.getBeanMap(o);
- } catch (Exception e) {
- throw new StrutsException("Caught an exception while getting the property values of " + o, e);
- }
- stackValues.add(new DebugMapEntry(o.getClass().getName(), values));
- }
+ ValueStack stack = getStack();
+ Iterator iter = stack.getRoot().iterator();
+ List stackValues = new ArrayList(stack.getRoot().size());
+ while (iter.hasNext()) {
+ Object o = iter.next();
+ Map values;
+ try {
+ values = reflectionProvider.getBeanMap(o);
+ } catch (Exception e) {
+ throw new StrutsException("Caught an exception while getting the property values of " + o, e);
+ }
+ stackValues.add(new DebugMapEntry(o.getClass().getName(), values));
+ }
- addParameter("stackValues", stackValues);
- }
+ addParameter("stackValues", stackValues);
+
return result;
}
@Override
public boolean end(Writer writer, String body) {
- if (showDebug()) {
- return super.end(writer, body);
- } else {
- popComponentStack();
- return false;
- }
- }
-
- protected boolean showDebug() {
- return (devMode || "false".equalsIgnoreCase(disabled));
+ if (!(devMode || "false".equalsIgnoreCase(disabled))) {
+ disabled = "true";
+ }
+ return super.end(writer, body);
}
private static class DebugMapEntry implements Map.Entry {
I have been tested above patch on this PR and passes all tests :)
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.
firstly, thank you to all
@lukaszlenart
...a pure client side thing. Right now it was used to control server side logic and I wonder if this is a good idea...
i see the problem, looking 4 a better solution
- debug.ftl change looks nice.
- Debug.java i would keep my version with the 'showDebug' methode for performance reason. If developer keep the DebugTag in the Jsp-files and defMode is disabled it always unnecessarily fetch the stackValues
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.
👍 I tested following patch on your PR which passes all tests also:
Index: core/src/main/resources/template/simple/debug.ftl
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/main/resources/template/simple/debug.ftl (date 1515941681000)
+++ core/src/main/resources/template/simple/debug.ftl (revision )
@@ -18,6 +18,8 @@
* under the License.
*/
-->
+<#if parameters.disabled!false>
+<#else >
<script type="text/javascript">
<!--
function toggleDebug(debugId) {
@@ -86,3 +88,4 @@
</#list>
</table>
</div>
+</#if>
\ No newline at end of file
Index: core/src/main/java/org/apache/struts2/components/Debug.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/main/java/org/apache/struts2/components/Debug.java (date 1515941681000)
+++ core/src/main/java/org/apache/struts2/components/Debug.java (revision )
@@ -41,6 +41,7 @@
protected ReflectionProvider reflectionProvider;
+
public Debug(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
}
@@ -57,7 +58,11 @@
public boolean start(Writer writer) {
boolean result = super.start(writer);
- if (showDebug()) {
+ if (!(devMode || "false".equalsIgnoreCase(disabled))) {
+ disabled = "true";
+ }
+
+ if (!"true".equalsIgnoreCase(disabled)) {
ValueStack stack = getStack();
Iterator iter = stack.getRoot().iterator();
List stackValues = new ArrayList(stack.getRoot().size());
@@ -74,23 +79,10 @@
addParameter("stackValues", stackValues);
}
+
return result;
}
- @Override
- public boolean end(Writer writer, String body) {
- if (showDebug()) {
- return super.end(writer, body);
- } else {
- popComponentStack();
- return false;
- }
- }
-
- protected boolean showDebug() {
- return (devMode || "false".equalsIgnoreCase(disabled));
- }
-
private static class DebugMapEntry implements Map.Entry {
private Object key;
private Object value;
…r this action only
|
||
return result; | ||
protected boolean showDebug() { | ||
return (devMode || Boolean.TRUE == PrepareOperations.getDevModeOverride()); |
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.
Ah! So you wanted to have an option to enable the <s:debug/>
on production that's why you had used the disabled
property. In such case getDevModeOverride
is a better choice 👍
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.
yes :-) , or more specifically for the Struts Showcase. 99 percent of users will not use it
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.
👍
I'm good with this PR 👍 if no objections please hit the button and I will prepare a new release :) |
one solution
if a user really wants to show the Debug Flag on his production release, he can use
<s:debug disabled="false"/>
got another solution 17b5984
this will solve the problem with client/server side control