Permalink
Browse files

Do not escape exception messages in variable substitution.

Moved TableTable.isExceptionFailureMessage() up to ScriptTable, so it can be used by Expectations.
  • Loading branch information...
amolenaar committed Nov 1, 2012
1 parent c646d74 commit 9414a8ffe0950aed2aea6b7b948ccf33c0067572
Showing with 13 additions and 7 deletions.
  1. +12 −2 src/fitnesse/slimTables/SlimTable.java
  2. +1 −5 src/fitnesse/slimTables/TableTable.java
@@ -306,6 +306,10 @@ protected boolean isExceptionMessage(String value) {
return value != null && (value.startsWith(SlimTestSystem.MESSAGE_FAIL) || value.startsWith(SlimTestSystem.MESSAGE_ERROR));
}
+ protected boolean isExceptionFailureMessage(String value) {
+ return value.startsWith("Exception: ");
+ }
+
public boolean shouldIgnoreException(String resultKey, String resultString) {
return false;
}
@@ -626,7 +630,11 @@ protected String createEvaluationMessage(String actual, String expected) {
protected String createEvaluationMessage(String actual, String expected) {
setSymbol(symbolName, actual);
- return String.format("$%s<-[%s]", symbolName, Utils.escapeHTML(actual));
+ if (isExceptionFailureMessage(actual)) {
+ return String.format("$%s<-[%s]", symbolName, actual);
+ } else {
+ return String.format("$%s<-[%s]", symbolName, Utils.escapeHTML(actual));
+ }
}
}
@@ -655,7 +663,7 @@ else if (replacedExpected.length() == 0)
String expressionMessage = new Comparator(this, replacedExpected, actual, expected).evaluate();
if (expressionMessage != null)
evaluationMessage = expressionMessage;
- else if (actual.contains("Exception:")) {
+ else if (isExceptionFailureMessage(actual)) {
evaluationMessage = error(actual);
} else
evaluationMessage = failMessage(actual,
@@ -870,4 +878,6 @@ private String matchSimpleComparison() {
return null;
}
}
+
+
}
@@ -2,7 +2,7 @@
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.slimTables;
-import static fitnesse.responders.run.slimResponder.SlimTestSystem.*;
+import static fitnesse.responders.run.slimResponder.SlimTestSystem.MESSAGE_ERROR;
import java.util.ArrayList;
import java.util.List;
@@ -46,10 +46,6 @@ public void evaluateReturnValues(Map<String, Object> returnValues) throws Except
resizeTableAndEvaluateRows(returnValues);
}
- private boolean isExceptionFailureMessage(String value) {
- return value.startsWith("Exception: ");
- }
-
private boolean isTestCaseErrorMessage(String value) {
return value.startsWith(MESSAGE_ERROR);
}

1 comment on commit 9414a8f

@stanio

This comment has been minimized.

Show comment Hide comment
@stanio

stanio Nov 3, 2012

Contributor

Seems the same test should be performed for formatSymbolValue (changed in 58b7000, also) as the variable may already have been assigned an "exception" value.

Try the following table:

|script|test script   |
|$VAR= |calculate|abc |
|$RES= |echo     |$VAR|

With the fixture code:

public class TestScript {

    public Object echo(Object value) {
        return value;
    }

    public Integer calculate(Integer value) {
        return value;
    }

}

The result is:

script test script
$VAR<-[Exception: scriptTable_0_1] calculate abc
$RES<-[$VAR] echo $VAR->[Exception: <a href=#scriptTable_0_1>scriptTable_0_1</a>]

I guess the following is the needed change:

diff --git a/src/fitnesse/slimTables/SlimTable.java b/src/fitnesse/slimTables/SlimTable.java
--- a/src/fitnesse/slimTables/SlimTable.java
+++ b/src/fitnesse/slimTables/SlimTable.java
@@ -570,16 +570,19 @@ public abstract class SlimTable {
   }

   class FullExpansionSymbolReplacer extends SymbolReplacer {
     FullExpansionSymbolReplacer(String s) {
       super(s);
     }

     protected String formatSymbolValue(String name, String value) {
+      if (isExceptionFailureMessage(value)) {
+        return String.format("$%s->[%s]", name, value);
+      }
       return String.format("$%s->[%s]", name, Utils.escapeHTML(value));
     }
   }

   public static class SyntaxError extends Error {
     private static final long serialVersionUID = 1L;

     public SyntaxError(String message) {

Contributor

stanio commented on 9414a8f Nov 3, 2012

Seems the same test should be performed for formatSymbolValue (changed in 58b7000, also) as the variable may already have been assigned an "exception" value.

Try the following table:

|script|test script   |
|$VAR= |calculate|abc |
|$RES= |echo     |$VAR|

With the fixture code:

public class TestScript {

    public Object echo(Object value) {
        return value;
    }

    public Integer calculate(Integer value) {
        return value;
    }

}

The result is:

script test script
$VAR<-[Exception: scriptTable_0_1] calculate abc
$RES<-[$VAR] echo $VAR->[Exception: <a href=#scriptTable_0_1>scriptTable_0_1</a>]

I guess the following is the needed change:

diff --git a/src/fitnesse/slimTables/SlimTable.java b/src/fitnesse/slimTables/SlimTable.java
--- a/src/fitnesse/slimTables/SlimTable.java
+++ b/src/fitnesse/slimTables/SlimTable.java
@@ -570,16 +570,19 @@ public abstract class SlimTable {
   }

   class FullExpansionSymbolReplacer extends SymbolReplacer {
     FullExpansionSymbolReplacer(String s) {
       super(s);
     }

     protected String formatSymbolValue(String name, String value) {
+      if (isExceptionFailureMessage(value)) {
+        return String.format("$%s->[%s]", name, value);
+      }
       return String.format("$%s->[%s]", name, Utils.escapeHTML(value));
     }
   }

   public static class SyntaxError extends Error {
     private static final long serialVersionUID = 1L;

     public SyntaxError(String message) {

Please sign in to comment.