Commit graph

184 commits

Author SHA1 Message Date
berni44
b2019ebab0 Narrow imports of std.math in the rest of phobos. 2021-04-21 03:00:57 +02:00
berni44
189a646286 Fix Issue 16432 - JSON incorrectly parses to string 2021-03-22 14:13:25 +01:00
berni44
6f2a0934a7 Adapt imports of std.format to new structure of std.format. 2021-03-19 13:22:00 +01:00
Crom (Thibaut CHARLES)
de28a13d54 Better wording & removed useless import 2020-12-03 19:42:10 +02:00
Crom (Thibaut CHARLES)
54c56ecb09 use std.conv.to to check for overflows 2020-12-03 19:42:10 +02:00
Crom (Thibaut CHARLES)
61a2fdd8f5 Add some conversions to JSONValue.get!T 2020-12-03 19:42:10 +02:00
Nathan Sashihara
453faadf5b Replace is(Unqual!T == Unqual!U) with is(immutable T == immutable U) for speed & memory usage 2020-08-03 15:07:32 +02:00
MoonlightSentinel
d816788da4
Fix Issue 20874 - std.json.assign requires '@safe' and 'pure' 2020-05-28 23:35:27 +02:00
Geod24
04f3979317 Replace 'Issue XXX' with Bugzilla links
Make the links clickable, as was done in the DMD repository.
Also avoids any ambiguity w.r.t. where the issue is stored.
2020-04-13 16:28:09 +09:00
aG0aep6G
9a91156f87 DRY 2020-03-10 02:40:07 +01:00
aG0aep6G
0bd2fa4334 mark access to value.store.str as @trusted
When issue 20655 ("attribute inference accepts unsafe union access as
@safe") is fixed, DMD correctly complains about the operation being unsafe.
2020-03-10 01:44:28 +01:00
Steven Schveighoffer
dbd4a2c0a5 Fix issue 20527. Set the correct union member for integers so CTFE
doesn't get confused.
2020-01-23 08:32:50 -05:00
Mathis Beer
3e26069a4f Fix issue 20511: make toJSON infer safeness based on output range safeness. 2020-01-17 06:26:51 +01:00
Martin Nowak
1589503ca0 Merge remote-tracking branch 'upstream/stable' into merge_stable 2019-12-16 10:52:16 +01:00
GrimMaple
8793b093bc Add get!(T) getter to std.json 2019-11-17 02:34:17 +03:00
Carsten Schlote
1479200267 Enhanced deprecation message on JSON_TYPE alias
Add hint to message to also change the enum members.
2019-11-03 11:39:29 +01:00
Carsten Schlote
ae03972df1 Fix Issue 20350 - Undeprecate JSONType member to avoid deprecation warnings
Undeprecate JSONType members, which create lots of spam-like
deprecation warnings, which can't be fixed by the user.

See discussion on this issue at
  https://forum.dlang.org/post/feudrhtxkaxxscwhhhff@forum.dlang.org
2019-11-03 11:39:12 +01:00
Robert Schadek
057d7ed326 Issue20330 json toString with OutRange
more style
2019-10-30 08:37:26 +00:00
Atila Neves
4cfef68d61 Replace in with const in preparation of dmd change
Changing dmd to implement `in` meaning `scope const` when DIP1000 is
selected causes Phobos to fail to compile. This changes Phobos in
preparation for that change.
2019-10-23 12:41:35 +02:00
Robert Schadek
53aa79c235 std_json allow trailing comma
* changelog
* annotate unittest
* with check for strict parsing
* tabs
2019-06-14 10:49:22 +01:00
Flying-Toast
11ebb6474b remove deprecated stuff in std.json 2019-05-18 21:23:42 -04:00
The Dlang Bot
76ef073df3
Merge pull request #6726 from FeepingCreature/fix/Issue-19297-handle-jsonvalue-signed-unsigned-comparison
Fix issue 19297: handle comparison of signed, unsigned and floating JSONValues as in D
merged-on-behalf-of: Vladimir Panteleev <github@thecybershadow.net>
2018-10-16 14:57:03 +02:00
Mathis Beer
b07b215424 Fix issue 19297: handle comparison of signed, unsigned and floating JSONValues 2018-10-11 10:47:28 +02:00
The Dlang Bot
3e3c65d9b9
Merge pull request #6682 from Erikvv/feature/json-boolean-getter-setter
Add a getter and setter for booleans in JSON
merged-on-behalf-of: Petar Kirov <ZombineDev@users.noreply.github.com>
2018-08-28 11:07:03 +02:00
Erik van Velzen
1992afb4b1 Remove inout for JSON getters of value types 2018-08-27 20:50:35 -04:00
Erik van Velzen
8e8409f308 Add a getter and setter for booleans in JSON 2018-08-27 20:54:32 +02:00
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