Commit Graph

53 Commits

Author SHA1 Message Date
John Schmidt
b1dd4b17d8 std.json: don't free struct default values
Closes https://github.com/ziglang/zig/issues/9509.
2023-02-04 20:51:15 +01:00
John Schmidt
b42caff2a2 std.json: avoid dangling pointers in ValueTree
Closes https://github.com/ziglang/zig/issues/5229.
2023-02-04 20:34:47 +01:00
John Schmidt
73c857415e std.json: fix parsing of structs with default value const pointers 2023-02-04 18:28:36 +01:00
Jon-Eric Cook
4c11684184
std.json: check output and source lengths in std.json 2023-01-28 16:26:36 +00:00
ominitay
889efddd1a std.json: Fix parsing of large numbers
Numbers greater than about 2^53 are encoded as strings in JSON.
std.json.parseInternal previously errored out in this condition.
2022-07-23 13:52:16 +03:00
Andrew Kelley
c9006d9479 std.json: move tests to json/test.zig file
This accomplishes two things:
 * Works around #8442 by putting stage1-specific logic in to disable all
   the std.json tests.
 * Slightly reduces installation size of zig since std lib files ending
   in "test.zig" are excluded from being installed.
2022-07-07 00:05:21 -07:00
May B
ea13437ac5
std.json: Support disabling indent (#11823)
Newline Delimited JSON (ndjson) expect compact json without newline inside its content
Add None to StringfyOptions.indent and move newline writeByte inside StringfyOptions.outputIndent
2022-06-29 11:53:01 +02:00
Lee Cannon
1093b09a98
allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
Lee Cannon
85de022c56
allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
Andrew Kelley
d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00
Matthew Borkowski
e902c19c0e
std/json: Fix premature closing brace being considered valid JSON
return error from StreamingParser when reading closing brace when expecting value for an object key
2021-05-13 11:11:28 +02:00
Veikka Tuominen
fd77f2cfed std: update usage of std.testing 2021-05-08 15:15:30 +03:00
xackus
a5007d819a std.meta: add isError 2021-04-11 16:26:29 +02:00
Lewis Gaul
7302b096bd
Tidy-up in json test module (#8431)
* Switch json testing 'roundTrip()' to use FixedBufferStream, improve error handling, remove comptime from param

* Add 'try' to calls to roundTrip() that can now return an error

* Remove comptime from params in json testing, replace expect(false) with letting error propagate

* Add 'try' to calls to ok() that can now return an error

Co-authored-by: Lewis Gaul <legaul@cisco.com>
2021-04-04 19:27:47 -04:00
Lewis Gaul
74fd7107e8
Switch std.json to use an ordered hashmap 2021-04-04 10:16:59 +02:00
daurnimator
d4af35b3fe HashMap.put returns !void, not a !bool 2021-02-27 13:11:47 +02:00
Jay Petacat
a9b505fa77 Reduce use of deprecated IO types
Related: #4917
2021-01-07 23:48:58 -08:00
Frank Denis
6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
xackus
21550bb7cd std.json: unreachable -> expect in tests 2020-12-08 19:16:17 -05:00
Tadeo Kondrak
25ec2dbc1e Add builtin.Signedness, use it instead of is_signed 2020-11-19 18:59:21 +02:00
LemonBoy
02efc2236a std: Fix json utf{8,16} decoding on BE targets
Byteswap some values when LE ordering is required.
2020-11-02 11:46:50 +01:00
Andrew Kelley
4a69b11e74 add license header to all std lib files
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
Vexu
e85fe13e44
run zig fmt on std lib and self hosted 2020-07-11 20:41:19 +03:00
Andrew Kelley
dd05f2be80 run zig fmt on std lib 2020-05-24 10:04:09 -04:00
Vexu
80d0c2f166
Merge pull request #5118 from xackus/fix-json-writestream
fix json.WriteStream.emitJson
2020-05-12 17:44:06 +03:00
Vexu
b1ebaba408
std.json properly handle comptime int/float 2020-05-12 15:15:21 +03:00
Timon Kruiper
c829f2f7b7 Add mips support to standard library 2020-04-24 15:28:55 -04:00
xackus
ebbd137a0e fix json.WriteStream.emitJson 2020-04-23 22:14:23 +02:00
daurnimator
7a3d700fd9
std: introduce json.WriteStream.stringify 2020-04-01 00:13:00 +11:00
daurnimator
42cabe4366
std: use json.StringifyOptions.Whitespace from json.WriteStream 2020-04-01 00:12:59 +11:00
daurnimator
17f5d04bed
std: use json.stringify logic in some json.WriteStream code paths 2020-04-01 00:12:59 +11:00
Andrew Kelley
9e7ae06249
std lib API deprecations for the upcoming 0.6.0 release
See #3811
2020-03-30 14:23:22 -04:00
xackus
d1202b1f66 fix overflow in parseFloat 2020-03-29 11:50:41 +02:00
Andrew Kelley
18f1fef142
update standard library to new I/O streams API 2020-03-10 18:44:30 -04:00
Andrew Kelley
ba0e3be5cf
(breaking) rework stream abstractions
The main goal here is to make the function pointers comptime, so that we
don't have to do the crazy stuff with async function frames.

Since InStream, OutStream, and SeekableStream are already generic
across error sets, it's not really worse to make them generic across the
vtable as well.

See #764 for the open issue acknowledging that using generics for these
abstractions is a design flaw.

See #130 for the efforts to make these abstractions non-generic.

This commit also changes the OutStream API so that `write` returns
number of bytes written, and `writeAll` is the one that loops until the
whole buffer is written.
2020-03-10 15:32:32 -04:00
daurnimator
6ea6d5a4bd
std: use testing.allocator in tests 2020-02-14 19:15:09 +11:00
Benjamin Feng
a81ae1223d Convert a lot of json tests to use testing.allocator 2020-02-12 17:17:56 -06:00
hryx
2933a8241a json: disallow overlong and out-of-range UTF-8
Fixes #2379

= Overlong (non-shortest) sequences

UTF-8's unique encoding scheme allows for some Unicode codepoints
to be represented in multiple ways. For any of these characters,
the spec forbids all but the shortest form. These disallowed longer
sequences are called "overlong". As an interesting side effect of
this rule, the bytes C0 and C1 never appear in valid UTF-8.

= Codepoint range

UTF-8 disallows representation of codepoints beyond U+10FFFF,
which is the highest character which can be encoded in UTF-16.
Because a 4-byte sequence is capable of resulting in such characters,
they must be explicitly rejected. This rule also has an interesting
side effect, which is that bytes F5 to FF never appear.

= References

Detecting an overlong version of a codepoint could get gnarly, but
luckily The Unicode Consortium did the hard work by creating this
handy table of valid byte sequences:

https://unicode.org/versions/corrigendum1.html

I thought this mapped nicely to the parser's state machine, so I
rearranged the relevant states to make use of it.
2020-01-07 12:07:44 -05:00
Andrew Kelley
53913acaf7
zig fmt and update extern fn to callconv(.C) 2020-01-06 15:34:50 -05:00
Andrew Kelley
54231e832b
Merge pull request #3648 from xackus/json-unescape
breaking: JSON unescape
2019-12-29 18:31:10 -05:00
Robin Voetter
4b4fbe3887
Replace @typeOf with @TypeOf in all zig source
This change was mostly made with `zig fmt` and this also modified some whitespace. Note that in some files, `zig fmt` produced incorrect code, so the change was made manually.
2019-12-10 11:09:41 -05:00
Andrew Kelley
8b2622cdd5
std.fmt.format: tuple parameter instead of var args 2019-12-08 22:53:51 -05:00
xackus
6d3b95a708 Stricter tests for non-streaming parser 2019-11-11 23:41:53 +01:00
xackus
f9b7d6d75d Fix bugs in JSON parser
Make comments into documentation where appropriate
2019-11-11 23:25:54 +01:00
xackus
371747d8fb json: surrogate pair support
test json.Parser with tests used for json.Streaming parser
(some don't pass yet)
2019-11-11 22:06:00 +01:00
Sebastian Keller
f81f36e2ff std.json.Value: added dumpStream(), utilize WriteStream for dump() 2019-11-06 18:21:52 -05:00
Sebastian Keller
78b00c0b51 Added test for 'emitJson' 2019-10-27 20:49:42 +01:00
Sebastian Keller
ac705a7bb6 Unified public api 2019-10-27 20:15:48 +01:00
Sebastian Keller
6257b4c596 Shortened switch statement 2019-10-24 22:44:12 +02:00
Sebastian Keller
b82b6a7093 Added 'writeJson' to write_stream.zig:
Small addition to make writing a json value easier
2019-10-24 14:23:36 +02:00