mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 11:25:30 -04:00
chore(#871-strictMode): reverted unrelated changes
This commit is contained in:
parent
f3b3491f4d
commit
3672b5e158
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -4,7 +4,6 @@ package org.json;
|
||||
* Configuration object for the JSON parser. The configuration is immutable.
|
||||
*/
|
||||
public class JSONParserConfiguration extends ParserConfiguration {
|
||||
|
||||
/**
|
||||
* Used to indicate whether to overwrite duplicate key or not.
|
||||
*/
|
||||
@ -34,9 +33,10 @@ public class JSONParserConfiguration extends ParserConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the maximum nesting depth that the parser will descend before throwing an exception when parsing a map
|
||||
* into JSONObject or parsing a {@link java.util.Collection} instance into JSONArray. The default max nesting depth
|
||||
* is 512, which means the parser will throw a JsonException if the maximum depth is reached.
|
||||
* Defines the maximum nesting depth that the parser will descend before throwing an exception
|
||||
* when parsing a map into JSONObject or parsing a {@link java.util.Collection} instance into
|
||||
* JSONArray. The default max nesting depth is 512, which means the parser will throw a JsonException
|
||||
* if the maximum depth is reached.
|
||||
*
|
||||
* @param maxNestingDepth the maximum nesting depth allowed to the JSON parser
|
||||
* @return The existing configuration will not be modified. A new configuration is returned.
|
||||
@ -51,8 +51,9 @@ public class JSONParserConfiguration extends ParserConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls the parser's behavior when meeting duplicate keys. If set to false, the parser will throw a
|
||||
* JSONException when meeting a duplicate key. Or the duplicate key's value will be overwritten.
|
||||
* Controls the parser's behavior when meeting duplicate keys.
|
||||
* If set to false, the parser will throw a JSONException when meeting a duplicate key.
|
||||
* Or the duplicate key's value will be overwritten.
|
||||
*
|
||||
* @param overwriteDuplicateKey defines should the parser overwrite duplicate keys.
|
||||
* @return The existing configuration will not be modified. A new configuration is returned.
|
||||
@ -83,8 +84,8 @@ public class JSONParserConfiguration extends ParserConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* The parser's behavior when meeting duplicate keys, controls whether the parser should overwrite duplicate keys or
|
||||
* not.
|
||||
* The parser's behavior when meeting duplicate keys, controls whether the parser should
|
||||
* overwrite duplicate keys or not.
|
||||
*
|
||||
* @return The <code>overwriteDuplicateKey</code> configuration value.
|
||||
*/
|
||||
|
@ -8,45 +8,28 @@ Public Domain.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A JSONTokener takes a source string and extracts characters and tokens from it. It is used by the JSONObject and
|
||||
* JSONArray constructors to parse JSON source strings.
|
||||
*
|
||||
* A JSONTokener takes a source string and extracts characters and tokens from
|
||||
* it. It is used by the JSONObject and JSONArray constructors to parse
|
||||
* JSON source strings.
|
||||
* @author JSON.org
|
||||
* @version 2014-05-03
|
||||
*/
|
||||
public class JSONTokener {
|
||||
|
||||
/**
|
||||
* current read character position on the current line.
|
||||
*/
|
||||
/** current read character position on the current line. */
|
||||
private long character;
|
||||
/**
|
||||
* flag to indicate if the end of the input has been found.
|
||||
*/
|
||||
/** flag to indicate if the end of the input has been found. */
|
||||
private boolean eof;
|
||||
/**
|
||||
* current read index of the input.
|
||||
*/
|
||||
/** current read index of the input. */
|
||||
private long index;
|
||||
/**
|
||||
* current line of the input.
|
||||
*/
|
||||
/** current line of the input. */
|
||||
private long line;
|
||||
/**
|
||||
* previous character read from the input.
|
||||
*/
|
||||
/** previous character read from the input. */
|
||||
private char previous;
|
||||
/**
|
||||
* Reader for the input.
|
||||
*/
|
||||
/** Reader for the input. */
|
||||
private final Reader reader;
|
||||
/**
|
||||
* flag to indicate that a previous character was requested.
|
||||
*/
|
||||
/** flag to indicate that a previous character was requested. */
|
||||
private boolean usePrevious;
|
||||
/**
|
||||
* the number of characters read in the previous line.
|
||||
*/
|
||||
/** the number of characters read in the previous line. */
|
||||
private long characterPreviousLine;
|
||||
|
||||
|
||||
@ -71,7 +54,6 @@ public class JSONTokener {
|
||||
|
||||
/**
|
||||
* Construct a JSONTokener from an InputStream. The caller must close the input stream.
|
||||
*
|
||||
* @param inputStream The source.
|
||||
*/
|
||||
public JSONTokener(InputStream inputStream) {
|
||||
@ -90,10 +72,11 @@ public class JSONTokener {
|
||||
|
||||
|
||||
/**
|
||||
* Back up one character. This provides a sort of lookahead capability, so that you can test for a digit or letter
|
||||
* before attempting to parse the next number or identifier.
|
||||
*
|
||||
* @throws JSONException Thrown if trying to step back more than 1 step or if already at the start of the string
|
||||
* Back up one character. This provides a sort of lookahead capability,
|
||||
* so that you can test for a digit or letter before attempting to parse
|
||||
* the next number or identifier.
|
||||
* @throws JSONException Thrown if trying to step back more than 1 step
|
||||
* or if already at the start of the string
|
||||
*/
|
||||
public void back() throws JSONException {
|
||||
if (this.usePrevious || this.index <= 0) {
|
||||
@ -119,8 +102,8 @@ public class JSONTokener {
|
||||
|
||||
/**
|
||||
* Get the hex value of a character (base16).
|
||||
*
|
||||
* @param c A character between '0' and '9' or between 'A' and 'F' or between 'a' and 'f'.
|
||||
* @param c A character between '0' and '9' or between 'A' and 'F' or
|
||||
* between 'a' and 'f'.
|
||||
* @return An int between 0 and 15, or -1 if c was not a hex digit.
|
||||
*/
|
||||
public static int dehexchar(char c) {
|
||||
@ -147,10 +130,11 @@ public class JSONTokener {
|
||||
|
||||
|
||||
/**
|
||||
* Determine if the source string still contains characters that next() can consume.
|
||||
*
|
||||
* Determine if the source string still contains characters that next()
|
||||
* can consume.
|
||||
* @return true if not yet at the end of the source.
|
||||
* @throws JSONException thrown if there is an error stepping forward or backward while checking for more data.
|
||||
* @throws JSONException thrown if there is an error stepping forward
|
||||
* or backward while checking for more data.
|
||||
*/
|
||||
public boolean more() throws JSONException {
|
||||
if(this.usePrevious) {
|
||||
@ -204,17 +188,13 @@ public class JSONTokener {
|
||||
|
||||
/**
|
||||
* Get the last character read from the input or '\0' if nothing has been read yet.
|
||||
*
|
||||
* @return the last character read from the input.
|
||||
*/
|
||||
protected char getPrevious() {
|
||||
return this.previous;
|
||||
}
|
||||
protected char getPrevious() { return this.previous;}
|
||||
|
||||
/**
|
||||
* Increments the internal indexes according to the previous character read and the character passed as the current
|
||||
* character.
|
||||
*
|
||||
* Increments the internal indexes according to the previous character
|
||||
* read and the character passed as the current character.
|
||||
* @param c the current character read.
|
||||
*/
|
||||
private void incrementIndexes(int c) {
|
||||
@ -237,8 +217,8 @@ public class JSONTokener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Consume the next character, and check that it matches a specified character.
|
||||
*
|
||||
* Consume the next character, and check that it matches a specified
|
||||
* character.
|
||||
* @param c The character to match.
|
||||
* @return The character.
|
||||
* @throws JSONException if the character does not match.
|
||||
@ -261,7 +241,9 @@ public class JSONTokener {
|
||||
*
|
||||
* @param n The number of characters to take.
|
||||
* @return A string of n characters.
|
||||
* @throws JSONException Substring bounds error if there are not n characters remaining in the source string.
|
||||
* @throws JSONException
|
||||
* Substring bounds error if there are not
|
||||
* n characters remaining in the source string.
|
||||
*/
|
||||
public String next(int n) throws JSONException {
|
||||
if (n == 0) {
|
||||
@ -284,9 +266,8 @@ public class JSONTokener {
|
||||
|
||||
/**
|
||||
* Get the next char in the string, skipping whitespace.
|
||||
*
|
||||
* @return A character, or 0 if there are no more characters.
|
||||
* @throws JSONException Thrown if there is an error reading the source string.
|
||||
* @return A character, or 0 if there are no more characters.
|
||||
*/
|
||||
public char nextClean() throws JSONException {
|
||||
for (;;) {
|
||||
@ -299,9 +280,10 @@ public class JSONTokener {
|
||||
|
||||
|
||||
/**
|
||||
* Return the characters up to the next close quote character. Backslash processing is done. The formal JSON format
|
||||
* does not allow strings in single quotes, but an implementation is allowed to accept them.
|
||||
*
|
||||
* Return the characters up to the next close quote character.
|
||||
* Backslash processing is done. The formal JSON format does not
|
||||
* allow strings in single quotes, but an implementation is allowed to
|
||||
* accept them.
|
||||
* @param quote The quoting character, either
|
||||
* <code>"</code> <small>(double quote)</small> or
|
||||
* <code>'</code> <small>(single quote)</small>.
|
||||
@ -364,11 +346,12 @@ public class JSONTokener {
|
||||
|
||||
|
||||
/**
|
||||
* Get the text up but not including the specified character or the end of line, whichever comes first.
|
||||
*
|
||||
* Get the text up but not including the specified character or the
|
||||
* end of line, whichever comes first.
|
||||
* @param delimiter A delimiter character.
|
||||
* @return A string.
|
||||
* @throws JSONException Thrown if there is an error while searching for the delimiter
|
||||
* @throws JSONException Thrown if there is an error while searching
|
||||
* for the delimiter
|
||||
*/
|
||||
public String nextTo(char delimiter) throws JSONException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@ -386,12 +369,12 @@ public class JSONTokener {
|
||||
|
||||
|
||||
/**
|
||||
* Get the text up but not including one of the specified delimiter characters or the end of line, whichever comes
|
||||
* first.
|
||||
*
|
||||
* Get the text up but not including one of the specified delimiter
|
||||
* characters or the end of line, whichever comes first.
|
||||
* @param delimiters A set of delimiter characters.
|
||||
* @return A string, trimmed.
|
||||
* @throws JSONException Thrown if there is an error while searching for the delimiter
|
||||
* @throws JSONException Thrown if there is an error while searching
|
||||
* for the delimiter
|
||||
*/
|
||||
public String nextTo(String delimiters) throws JSONException {
|
||||
char c;
|
||||
@ -542,8 +525,6 @@ public class JSONTokener {
|
||||
}
|
||||
|
||||
Object nextSimpleValue(char c, boolean strictMode) {
|
||||
String string;
|
||||
|
||||
if (c == '"' || c == '\'') {
|
||||
String str = this.nextString(c);
|
||||
if (strictMode) {
|
||||
@ -552,6 +533,19 @@ public class JSONTokener {
|
||||
return str;
|
||||
}
|
||||
|
||||
return parsedUnquotedText(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses unquoted text from the JSON input. This could be the values true, false, or null, or it can be a number.
|
||||
* Non-standard forms are also accepted. Characters are accumulated until the end of the text or a formatting
|
||||
* character is reached.
|
||||
*
|
||||
* @param c The starting character.
|
||||
* @return The parsed object.
|
||||
* @throws JSONException If the parsed string is empty.
|
||||
*/
|
||||
private Object parsedUnquotedText(char c) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
|
||||
sb.append(c);
|
||||
@ -561,8 +555,8 @@ public class JSONTokener {
|
||||
this.back();
|
||||
}
|
||||
|
||||
string = sb.toString().trim();
|
||||
if ("".equals(string)) {
|
||||
String string = sb.toString().trim();
|
||||
if (string.isEmpty()) {
|
||||
throw this.syntaxError("Missing value");
|
||||
}
|
||||
return JSONObject.stringToValue(string);
|
||||
@ -570,12 +564,13 @@ public class JSONTokener {
|
||||
|
||||
|
||||
/**
|
||||
* Skip characters until the next character is the requested character. If the requested character is not found, no
|
||||
* characters are skipped.
|
||||
*
|
||||
* Skip characters until the next character is the requested character.
|
||||
* If the requested character is not found, no characters are skipped.
|
||||
* @param to A character to skip to.
|
||||
* @return The requested character, or zero if the requested character is not found.
|
||||
* @throws JSONException Thrown if there is an error while searching for the to character
|
||||
* @return The requested character, or zero if the requested character
|
||||
* is not found.
|
||||
* @throws JSONException Thrown if there is an error while searching
|
||||
* for the to character
|
||||
*/
|
||||
public char skipTo(char to) throws JSONException {
|
||||
char c;
|
||||
|
@ -2,7 +2,6 @@ package org.json.junit;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@ -14,7 +13,6 @@ import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class JSONParserConfigurationTest {
|
||||
|
||||
private static final String TEST_SOURCE = "{\"key\": \"value1\", \"key\": \"value2\"}";
|
||||
|
||||
@Test(expected = JSONException.class)
|
||||
|
Loading…
x
Reference in New Issue
Block a user