Skip to content

[feature] allow user custom max depth #155

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

Closed
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 @@ -93,6 +93,10 @@ abstract class JSONParserBase {
protected final boolean unrestictBigDigit;

public JSONParserBase(int permissiveMode) {
this(permissiveMode, new ParserOptions());
}

public JSONParserBase(int permissiveMode, ParserOptions parserOptions) {
this.acceptNaN = (permissiveMode & JSONParser.ACCEPT_NAN) > 0;
this.acceptNonQuote = (permissiveMode & JSONParser.ACCEPT_NON_QUOTE) > 0;
this.acceptSimpleQuote = (permissiveMode & JSONParser.ACCEPT_SIMPLE_QUOTE) > 0;
Expand All @@ -103,7 +107,7 @@ public JSONParserBase(int permissiveMode) {
this.useHiPrecisionFloat = (permissiveMode & JSONParser.USE_HI_PRECISION_FLOAT) > 0;
this.checkTaillingData = (permissiveMode & (JSONParser.ACCEPT_TAILLING_DATA
| JSONParser.ACCEPT_TAILLING_SPACE)) != (JSONParser.ACCEPT_TAILLING_DATA
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my screen is not large enough to read this line ...
may I get a human translation for this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@UrielCh It's a style miss change. I will revert it.

| JSONParser.ACCEPT_TAILLING_SPACE);
| JSONParser.ACCEPT_TAILLING_SPACE);
this.checkTaillingSpace = (permissiveMode & JSONParser.ACCEPT_TAILLING_SPACE) == 0;
this.reject127 = (permissiveMode & JSONParser.REJECT_127_CHAR) > 0;
this.unrestictBigDigit = (permissiveMode & JSONParser.BIG_DIGIT_UNRESTRICTED) > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public JSONParserByteArray(int permissiveMode) {
super(permissiveMode);
}

public JSONParserByteArray(int permissiveMode, ParserOptions parserOptions) {
super(permissiveMode, parserOptions);
}

/**
* use to return Primitive Type, or String, Or JsonObject or JsonArray
* generated by a ContainerFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public JSONParserInputStream(int permissiveMode) {
super(permissiveMode);
}

public JSONParserInputStream(int permissiveMode, ParserOptions parserOptions) {
super(permissiveMode, parserOptions);
}

/**
* use to return Primitive Type, or String, Or JsonObject or JsonArray
* generated by a ContainerFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public JSONParserMemory(int permissiveMode) {
super(permissiveMode);
}

public JSONParserMemory(int permissiveMode, ParserOptions parserOptions) {
super(permissiveMode, parserOptions);
}

protected void readNQString(boolean[] stop) throws IOException {
int start = pos;
skipNQString(stop);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public JSONParserReader(int permissiveMode) {
super(permissiveMode);
}

public JSONParserReader(int permissiveMode, ParserOptions parserOptions) {
super(permissiveMode, parserOptions);
}

/**
* use to return Primitive Type, or String, Or JsonObject or JsonArray
* generated by a ContainerFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public JSONParserStream(int permissiveMode) {
super(permissiveMode);
}

public JSONParserStream(int permissiveMode, ParserOptions parserOptions) {
super(permissiveMode, parserOptions);
}

protected void readNQString(boolean[] stop) throws IOException {
sb.clear();
skipNQString(stop);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public JSONParserString(int permissiveMode) {
super(permissiveMode);
}

public JSONParserString(int permissiveMode, ParserOptions parserOptions) {
super(permissiveMode, parserOptions);
}

/**
* use to return Primitive Type, or String, Or JsonObject or JsonArray
* generated by a ContainerFactory
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.minidev.json.parser;

/*
* Copyright 2011-2023 JSON-SMART authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class ParserOptions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding a flag to remove the limit can be enough?

adding and extra ParserOptions only for that, is... overkill ?

and this PR looks not to use maxDepth.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@UrielCh Yes, as I said before, it's only a draft about external API changes.


private int maxDepth;

public ParserOptions() {
}

public int getMaxDepth() {
return maxDepth;
}

public void setMaxDepth(int maxDepth) {
this.maxDepth = maxDepth;
}
}