Skip to content
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

Fix for WFCORE-2936. Handle empty string in complex object #2529

Merged
merged 1 commit into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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