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

[DRAFT] validate deep nesting #394

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,8 @@ public Object getInputSource() {
* We need to override this method to support coercion from basic
* String value into array, in cases where schema does not
* specify actual type.
*
* @throws UncheckedIOException if the nesting depth is too large, see {@link StreamReadConstraints.Builder#maxNestingDepth(int)}
*/
@Override
public boolean isExpectedStartArrayToken() {
Expand All @@ -641,19 +643,24 @@ public boolean isExpectedStartArrayToken() {
case JsonTokenId.ID_START_ARRAY:
return true;
}
// Otherwise: may coerce into array, iff we have essentially "untyped" column
if (_columnIndex < _columnCount) {
CsvSchema.Column column = _schema.column(_columnIndex);
if (column.getType() == CsvSchema.ColumnType.STRING) {
_startArray(column);
try {
// Otherwise: may coerce into array, iff we have essentially "untyped" column
if (_columnIndex < _columnCount) {
CsvSchema.Column column = _schema.column(_columnIndex);
if (column.getType() == CsvSchema.ColumnType.STRING) {
_startArray(column);
return true;
}
}
// 30-Dec-2014, tatu: Seems like it should be possible to allow this
// in non-array-wrapped case too (for 2.5), so let's try that:
else if (_currToken == JsonToken.VALUE_STRING) {
_startArray(CsvSchema.Column.PLACEHOLDER);
return true;
}
}
// 30-Dec-2014, tatu: Seems like it should be possible to allow this
// in non-array-wrapped case too (for 2.5), so let's try that:
else if (_currToken == JsonToken.VALUE_STRING) {
_startArray(CsvSchema.Column.PLACEHOLDER);
return true;

} catch (IOException e) {
throw new UncheckedIOException(e);
}
return false;
}
Expand Down Expand Up @@ -926,13 +933,15 @@ protected JsonToken _handleStartDoc() throws IOException
// but even empty sequence must still be wrapped in logical array
if (wrapAsArray) {
_parsingContext = _reader.childArrayContext(_parsingContext);
_streamReadConstraints.validateNestingDepth(_parsingContext.getNestingDepth());
return JsonToken.START_ARRAY;
}
return null;
}

if (wrapAsArray) {
_parsingContext = _reader.childArrayContext(_parsingContext);
_streamReadConstraints.validateNestingDepth(_parsingContext.getNestingDepth());
_state = STATE_RECORD_START;
return JsonToken.START_ARRAY;
}
Expand All @@ -946,10 +955,12 @@ protected JsonToken _handleRecordStart() throws IOException
if (_columnCount == 0) { // no schema; exposed as an array
_state = STATE_UNNAMED_VALUE;
_parsingContext = _reader.childArrayContext(_parsingContext);
_streamReadConstraints.validateNestingDepth(_parsingContext.getNestingDepth());
return JsonToken.START_ARRAY;
}
// otherwise, exposed as an Object
_parsingContext = _reader.childObjectContext(_parsingContext);
_streamReadConstraints.validateNestingDepth(_parsingContext.getNestingDepth());
_state = STATE_NEXT_ENTRY;
return JsonToken.START_OBJECT;
}
Expand Down Expand Up @@ -1403,11 +1414,12 @@ public ByteArrayBuilder _getByteArrayBuilder()
return _byteArrayBuilder;
}

protected void _startArray(CsvSchema.Column column)
protected void _startArray(CsvSchema.Column column) throws IOException
{
_currToken = JsonToken.START_ARRAY;
_parsingContext = _parsingContext.createChildArrayContext(_reader.getCurrentRow(),
_reader.getCurrentColumn());
_streamReadConstraints.validateNestingDepth(_parsingContext.getNestingDepth());
_state = STATE_IN_ARRAY;
_arrayValueStart = 0;
_arrayValue = _currentValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public JPropReadContext(int contextType, JPropReadContext p, JPropNode node)
_index = -1;
_parent = p;
_branchText = node.getValue();
_nestingDepth = p == null ? 0 : p._nestingDepth + 1;
}

public static JPropReadContext create(JPropNode root) {
Expand Down