Commit graph

208 commits

Author SHA1 Message Date
Mathis Beer
fbd094737f Fix Issue 19135
Rewrite std.json.JSON_TYPE to be CamelCase with lowercase members, with underscore attached to avoid keyword collision.
Deprecate the old type via alias.
2018-08-08 08:34:00 +02:00
Tyler Knott
20353df3d9 Fix issue 16639 - Review std.json wrt this article on JSON edge cases and ambiguities
The test corpus provided at https://github.com/nst/JSONTestSuite/ revealed some issues with the std.json.parseJSON function. Since addressing some of the issues required parseJSON to reject input it previously accepted, I have added a new JSONOptions.strictParsing flag so callers can opt-in to the stricter parsing.

The issues, and how I've addressed them, are listed below (approximately from most severe to least):

Silently dropping ASCII NUL characters from strings:
n_string_unescaped_crtl_char.json

This is the most serious problem I found while fixing the test cases. The current implementation of parseJSON() uses a helper function called peekChar() which can store the next character to handle in a variable of type Char (an alias of the character type). Unfortunately it was using 0 to indicate it has not read a character yet so if an ASCII NUL (which will have the value 0) is present in the text and someone reads it with peekChar() then it will effectively be skipped over, which was happening in string and whitespace parsing.

I changed peekChar() to use a Nullable!Char as the temporary storage for the next character to disambiguate the case where there is no pending unconsumed character from the case where there is a pending unconsumed ASCII NUL. In strict mode JSON with unescaped ASCII NULs in strings will throw an exception while in non-strict mode the JSON will be accepted with the NUL included in the string value.

Failure to accept ASCII DEL (0x7f) unescaped in strings:
y_string_unescaped_char_delete.json
y_string_with_del_character.json

These were the only test cases that std.json rejected that it should have accepted. This issue was addressed by changing the string parsing logic to explicitly check for character values < 0x20 instead of using std.ascii.isControl (which also returned true for 0x7f), with a special exception for ASCII NULs in non-strict mode as mentioned above.

Parsing "true", "false", and "null" tokens case-insensitively:
n_structure_capitalized_True.json

In strict mode those tokens are now parsed case-sensitively.

Accepting control characters other than ' ', '\t', '\r', and '\n' as whitespace:
n_structure_null-byte-outside-string.json
n_structure_whitespace_formfeed.json

In strict mode only the listed characters are accepted as whitespace, while non-strict mode continues to use std.ascii.isWhite with an additional exception for ASCII NUL for a similar reason as the n_string_unescaped_ctrl_char.json case (the skipWhitespace() function used peekChar() so it didn't handle ASCII NULs consistently; non-strict mode after my changes is actually more permissive than the previous behavior but it is at least consistently permissive).

Silently accepting empty data:
n_structure_no_data.json

In strict mode an exception is now thrown instead of returning an empty value.

Failure to enforce that numbers beginning with 0 cannot have any additional digits in the non-fractional part:
n_number_-01.json
n_number_neg_int_starting_with_zero.json
n_number_with_leading_zero.json

An additional check is now performed in strict mode when the whole part of a number begins with zero to ensure trailing digits are not present.

Failure to check for trailing characters after parsing:
n_array_comma_after_close.json
n_array_extra_close.json
n_multidigit_number_then_00.json
n_object_trailing_comment.json
n_object_trailing_comment_open.json
n_object_trailing_comment_slash_open_incomplete.json
n_object_trailing_comment_slash_open.json
n_object_with_trailing_garbage.json
n_string_with_trailing_garbage.json
n_structure_array_trailing_garbage.json
n_structure_array_with_extra_array_close.json
n_structure_close_unopened_array.json
n_structure_double_array.json
n_structure_number_with_trailing_garbage.json
n_structure_object_followed_by_closing_object.json
n_structure_object_with_trailing_garbage.json
n_structure_trailing_#.json

An additional check is now performed in strict mode to ensure any trailing characters after the initial JSON value are only whitespace.

In addition to the above issues, parseJSON() will throw ConvException for numbers out of the range of double/long/ulong which was not previously documented. I have updated the ddoc comment to reference that exception.
2018-06-27 21:29:00 -05:00
Sebastian Wilzbach
c324714fde Remove a few cases of underscore escaping 2018-06-04 13:05:01 +02:00
Sebastian Wilzbach
42894784dd Markdownify Phobos
$(D word) -> `word`
2018-04-02 22:32:47 +02:00
Sebastian Wilzbach
611e62c96f Turn enforce into an eponymous template + undocument enforceEx 2018-02-07 01:01:59 +01:00
Sebastian Wilzbach
b121fc9105
Revert "Turn enforce into an eponymous template + undocument enforceEx" 2018-02-06 16:55:28 +01:00
Sebastian Wilzbach
78dcc91e57 Replace enforceEx with enforce 2018-02-02 15:50:10 +01:00
Dragos Carp
d1b1afb92b
Fix ddoc in std.json
Otherwise generated documentation contains hml source pieces like:
"json.html#.JSONException">std.json.JSONException if the depth exceeds the max depth."

see: https://dlang.org/phobos/std_json.html#.parseJSON.2
2017-12-22 00:55:18 +01:00
Sebastian Wilzbach
2591b61b4f Start removing std.{json,zip,zlib,algorithm.mutation}
from the assert_without_msg blacklist
2017-12-01 09:28:05 +01:00
Basile Burg
7ee287a69f
Remove toJSON overload planned for removal this month 2017-11-03 11:24:14 +01:00
anonymous
59a32d50ac code formatting 2017-07-08 23:42:56 +02:00
anonymous
0503b9b4a5 add JSONOptions.doNotEscapeSlashes
Fixes issue 17587 (enhancement request).
2017-07-08 20:45:19 +02:00
Sebastian Wilzbach
3b9fbff15a Fix style (space between a .. b) in std/json.d 2017-07-06 00:44:59 +02:00
Vladimir Panteleev
71875c0903 std.json: Fix handling ranges of non-dchars 2017-06-26 18:52:22 +00:00
Vladimir Panteleev
5031ff1446 Fix Issue 17553 - std.json should not do UTF decoding when encoding JSON 2017-06-26 18:52:18 +00:00
Vladimir Panteleev
226f8e001c Fix Issue 17557 - std.json should not do UTF decoding when parsing 2017-06-26 12:21:04 +00:00
Vladimir Panteleev
b23e7a4107 Fix Issue 5904 - std.json parseString doesn't handle chars outside the BMP 2017-06-26 12:05:44 +00:00
Vladimir Panteleev
b3399112ca std.json: Refactor parsing Unicode character escapes into a new function 2017-06-26 12:05:44 +00:00
Vladimir Panteleev
941e2936b6 Fix Issue 17556 - std.json encodes non-BMP characters incorrectly with JSONOptions.escapeNonAsciiChars 2017-06-26 12:05:44 +00:00
Vladimir Panteleev
e44666fc51 std.json: Inline appendJSONChar
Since the previous commit, it was only called from one place.
2017-06-26 12:05:44 +00:00
Vladimir Panteleev
55aa34e440 Fix Issue 17555 - [REG2.070.0] Control characters in JSON data are invalid and should cause an exception 2017-06-26 12:05:44 +00:00
Vladimir Panteleev
145f279b42 std.json: Remove unused error parameter to appendJSONChar 2017-06-26 08:09:06 +00:00
The Dlang Bot
857fdc1312 Merge pull request #5486 from wilzbach/fix-ddoc
Fix invalid undefined Ddoc macros
merged-on-behalf-of: Vladimir Panteleev <github@thecybershadow.net>
2017-06-15 17:39:23 +02:00
Sebastian Wilzbach
e7111d4fd0 Fix invalid undefined Ddoc macros 2017-06-15 11:00:47 +02:00
Vladimir Panteleev
d0b9555a06
Revert "Sort selective imports"
This reverts commit 998ad51fd7.
2017-06-13 17:51:52 +00:00
Sebastian Wilzbach
998ad51fd7 Sort selective imports 2017-06-12 08:12:09 +02:00
Sebastian Wilzbach
61717ecc7d Sort imports 2017-06-12 07:54:38 +02:00
Martin
13ca4ddac7 Relax a few unittests for double-precision reals
A loss-less roundtrip (to string <=> parse) apparently isn't guaranteed
when using double-precision reals.
2017-05-24 23:51:54 +02:00
Sebastian Wilzbach
425ab667a3 Automatically set the range style from a..b -> a .. b
Commands:

sed -E "s/([[:alnum:]])[.][.]([[:alnum:]])/\1 .. \2/g" -i **/*.d
sed -E "s/([[:alnum:]])[.][.] ([[:alnum:]])/\1 .. \2/g" -i **/*.d
sed -E "s/([[:alnum:]]) [.][.]([[:alnum:]])/\1 .. \2/g" -i **/*.d
2017-02-22 05:37:31 +01:00
Sebastian Wilzbach
805c720595 Unify Phobos by ensuring there's always a space after cast(...)
Command:

sed -E 's/([^"])cast\(([^)]*?)\)([[:alnum:]])/\1cast(\2) \3/g' -i **/*.d
2017-02-21 16:40:20 +01:00
Jack Stouffer
395ae88ac7 Merge pull request #5146 from JackStouffer/isInfinite
Add checks for infinite ranges in many range function signitures (part 3)
2017-02-17 13:06:46 -05:00
Jack Stouffer
6a2d51238f Add checks for infinite ranges in many range function signitures 2017-02-17 11:14:38 -05:00
Sebastian Wilzbach
31c4226042 Fix deprecation: std.utf.toUTF8 -> encode 2017-02-17 11:02:46 +01:00
Walter Bright
0cc2d6fa35 std.json: use proper block comments 2017-02-09 12:39:55 -08:00
Sebastian Wilzbach
cc7f125ed1 Add missing imports to public unittests 2016-12-15 23:23:35 +01:00
Jack Stouffer
4cad2fc326 Remove package wide std.algorithm imports from std/json.d 2016-09-20 11:08:21 +01:00
Walter Bright
55e5737525 add 'scope' to opApply() parameter 2016-09-14 19:41:41 -07:00
Walter Bright
fc8e5f29be Merge pull request #4605 from jmdavis/deprecations
Move deprecations along
2016-07-19 01:29:24 -07:00
Walter Bright
50d0023bb3 json.d: union pointer access is unsafe 2016-07-18 20:01:05 -07:00
Jonathan M Davis
1add09c180 Move deprecations along. 2016-07-18 14:56:03 -07:00
Walter Bright
f6ad90e511 Merge pull request #4513 from JackStouffer/local_imports
Start work on checking of too broad local imports outside of unit tests
2016-07-01 20:24:23 -07:00
Atila Neves
08dcaae62c Add @system and @safe to std.json unit tests 2016-07-01 19:03:01 +02:00
Jack Stouffer
c7a65ca81d Fixed local imports in std.json 2016-06-30 18:07:01 -04:00
Sebastian Wilzbach
6982cdc511 fix top-level json.d example 2016-06-29 19:53:02 +02:00
Sebastian Wilzbach
ec47ac4224 Remove the WEB macro in favor of HTTP
replacement: sed 's/\$(WEB/\$(HTTP/g' -i **/*.d
2016-06-16 00:14:51 +02:00
Sebastian Wilzbach
a37a5a9896 Fix more 404s links 2016-06-06 04:29:23 +02:00
tsbockman
7a486d9d03 Fix issue 15885 - numeric values serialized to JSON lose precision. 2016-05-31 21:21:59 -07:00
Sebastian Wilzbach
1d34a121e9 apply all-man braces in Phobos
// find common cases
sed -E "s/^(\s*)((if|static if|for|foreach|foreach_reverse|while|unittest|switch|else|version).*)\s*\{$/\1\2\n\1{/" -i **/*.d
// catch else-if
sed -E "s/^(\s*)} (else static if| if|else if|else)(.*)\s*\{$/\1}\n\1\2\3\n\1{/" -i **/*.d
// remove created trailing whitespace
sed -i 's/[ \t]*$//' **/*.d
2016-05-31 13:07:53 +02:00
Sebastian Wilzbach
2dfbc51f17 Standardize whitespace after imports
Unified with:

sed -E "s/import\s*([^ ]+)\s*:\s*(.*(,|;))/import \1 : \2/" -i **/*.d
2016-05-29 22:09:56 +02:00
anonymous
764caefa36 XREF -> REF (sed)
Done by:

(find . -type f -name "*.d" -print0; \
    find . -type f -name "*.dd" -print0) | \
xargs -0 sed -i -r \
    's/\$\(XREF\s+([^(),]*),\s*([^(),]*)\)/$(REF \2, std,\1)/g'
2016-05-27 21:32:46 +02:00