Skip to content

Commit

Permalink
Merge pull request #2529 from jfdenise/WFCORE-2936
Browse files Browse the repository at this point in the history
Fix for WFCORE-2936. Handle empty string in complex object
  • Loading branch information
bstansberry committed Jun 14, 2017
2 parents 1a52675 + bad7fbf commit 2d977c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void leavingState(ParsingContext ctx) throws CommandFormatException {
}
} else if(QuotesState.ID.equals(stateId)) {
flag ^= QUOTES;
currentState.quoted();
} else if(EscapeCharacterState.ID.equals(stateId)) {
flag ^= ESCAPE;
}
Expand Down Expand Up @@ -169,6 +170,9 @@ interface ValueState {
boolean isOnSeparator();

void enteredValue();

default void quoted() {
}
}

class BytesState implements ValueState {
Expand Down Expand Up @@ -259,6 +263,7 @@ class DefaultValueState implements ValueState {
protected boolean onSeparator;

protected ModelNode child;
private boolean quoted;

@Override
public boolean isOnSeparator() {
Expand Down Expand Up @@ -348,6 +353,9 @@ private ModelNode getStringValue() {
final ModelNode value = new ModelNode();
if(buf != null) {
value.set(getTrimmedString());
} else if (quoted) {
// An empty String, just composed of 2 quotes.
value.set("");
}
return value;
}
Expand All @@ -364,6 +372,11 @@ protected String getTrimmedString() {
}
return buf.toString();
}

@Override
public void quoted() {
quoted = true;
}
}

class ListValueState implements ValueState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ public void testObject_TextValue() throws Exception {
assertEquals("text", value.asString());
}

@Test
public void testObject_TextEmptyValue() throws Exception {
final ModelNode obj = parseObject("{x=\"\"}");
assertNotNull(obj);
assertEquals(ModelType.OBJECT, obj.getType());
ModelNode val = obj.get("x");
assertEquals(ModelType.STRING, val.getType());
assertEquals("", val.asString());
}

protected ModelNode parseObject(String value) throws CommandFormatException {
return ArgumentValueConverter.DEFAULT.fromString(ctx, value);
}
Expand Down

0 comments on commit 2d977c8

Please sign in to comment.