Thomas Pelletier
8a416daa69
Fix error report of type mismatch on inline tables ( #853 )
...
Parser did not track the location of the faulty inline table in the
document, and unmarshaler tried to the use the non-raw data field of the
AST node, both resulting into a panic when generating the parser error.
Fixes #850
2023-02-28 17:06:49 +01:00
Andreas Deininger
fcd9179b7d
Fixes typos ( #849 )
2023-02-13 03:57:48 -08:00
Thomas Pelletier
28f1efc7d3
Decode: don't break on non-struct embed field ( #810 )
2022-08-22 18:39:11 -04:00
Thomas Pelletier
e46d245c09
Decode: don't crash on embedded nil pointers ( #808 )
...
Also has the perks of reducing the overhead of FindByIndex:
```
name old time/op new time/op delta
UnmarshalDataset/config-32 17.0ms ± 1% 17.0ms ± 1% ~ (p=1.000 n=5+5)
UnmarshalDataset/canada-32 71.6ms ± 1% 71.4ms ± 1% ~ (p=1.000 n=5+5)
UnmarshalDataset/citm_catalog-32 24.2ms ± 3% 23.5ms ± 2% -3.03% (p=0.032 n=5+5)
UnmarshalDataset/twitter-32 9.37ms ± 1% 9.09ms ± 2% -2.97% (p=0.032 n=5+5)
UnmarshalDataset/code-32 75.4ms ± 2% 74.9ms ± 0% ~ (p=0.222 n=5+5)
UnmarshalDataset/example-32 147µs ±10% 136µs ± 1% -7.14% (p=0.008 n=5+5)
Unmarshal/SimpleDocument/struct-32 512ns ± 2% 500ns ± 0% -2.35% (p=0.008 n=5+5)
Unmarshal/SimpleDocument/map-32 721ns ± 2% 702ns ± 1% -2.68% (p=0.008 n=5+5)
Unmarshal/ReferenceFile/struct-32 40.1µs ± 0% 39.6µs ± 0% -1.30% (p=0.008 n=5+5)
Unmarshal/ReferenceFile/map-32 62.3µs ± 1% 60.6µs ± 0% -2.83% (p=0.008 n=5+5)
Unmarshal/HugoFrontMatter-32 10.8µs ± 1% 10.5µs ± 1% -2.86% (p=0.008 n=5+5)
name old speed new speed delta
UnmarshalDataset/config-32 61.8MB/s ± 1% 61.8MB/s ± 1% ~ (p=1.000 n=5+5)
UnmarshalDataset/canada-32 30.8MB/s ± 1% 30.8MB/s ± 1% ~ (p=1.000 n=5+5)
UnmarshalDataset/citm_catalog-32 23.0MB/s ± 3% 23.8MB/s ± 2% +3.09% (p=0.032 n=5+5)
UnmarshalDataset/twitter-32 47.2MB/s ± 1% 48.6MB/s ± 2% +3.09% (p=0.032 n=5+5)
UnmarshalDataset/code-32 35.6MB/s ± 2% 35.9MB/s ± 0% ~ (p=0.222 n=5+5)
UnmarshalDataset/example-32 55.3MB/s ±10% 59.4MB/s ± 1% +7.36% (p=0.008 n=5+5)
Unmarshal/SimpleDocument/struct-32 21.5MB/s ± 2% 22.0MB/s ± 0% +2.41% (p=0.008 n=5+5)
Unmarshal/SimpleDocument/map-32 15.2MB/s ± 2% 15.7MB/s ± 1% +2.74% (p=0.008 n=5+5)
Unmarshal/ReferenceFile/struct-32 131MB/s ± 0% 132MB/s ± 0% +1.31% (p=0.008 n=5+5)
Unmarshal/ReferenceFile/map-32 84.1MB/s ± 1% 86.6MB/s ± 0% +2.91% (p=0.008 n=5+5)
Unmarshal/HugoFrontMatter-32 50.6MB/s ± 1% 52.1MB/s ± 1% +2.93% (p=0.008 n=5+5)
name old alloc/op new alloc/op delta
UnmarshalDataset/config-32 5.86MB ± 0% 5.86MB ± 0% ~ (p=0.579 n=5+5)
UnmarshalDataset/canada-32 83.0MB ± 0% 83.0MB ± 0% ~ (p=0.651 n=5+5)
UnmarshalDataset/citm_catalog-32 34.7MB ± 0% 34.7MB ± 0% ~ (p=0.548 n=5+5)
UnmarshalDataset/twitter-32 12.7MB ± 0% 12.7MB ± 0% ~ (p=1.000 n=5+5)
UnmarshalDataset/code-32 22.2MB ± 0% 22.2MB ± 0% ~ (p=0.841 n=5+5)
UnmarshalDataset/example-32 186kB ± 0% 186kB ± 0% ~ (p=0.111 n=5+5)
Unmarshal/SimpleDocument/struct-32 805B ± 0% 805B ± 0% ~ (all equal)
Unmarshal/SimpleDocument/map-32 1.13kB ± 0% 1.13kB ± 0% ~ (all equal)
Unmarshal/ReferenceFile/struct-32 20.9kB ± 0% 20.9kB ± 0% ~ (p=0.643 n=5+5)
Unmarshal/ReferenceFile/map-32 38.3kB ± 0% 38.3kB ± 0% ~ (p=0.397 n=5+5)
Unmarshal/HugoFrontMatter-32 7.44kB ± 0% 7.44kB ± 0% ~ (all equal)
name old allocs/op new allocs/op delta
UnmarshalDataset/config-32 227k ± 0% 227k ± 0% ~ (p=1.000 n=5+5)
UnmarshalDataset/canada-32 782k ± 0% 782k ± 0% ~ (all equal)
UnmarshalDataset/citm_catalog-32 192k ± 0% 192k ± 0% ~ (p=0.968 n=4+5)
UnmarshalDataset/twitter-32 56.9k ± 0% 56.9k ± 0% ~ (p=0.429 n=4+5)
UnmarshalDataset/code-32 1.05M ± 0% 1.05M ± 0% ~ (p=0.556 n=4+5)
UnmarshalDataset/example-32 1.36k ± 0% 1.36k ± 0% ~ (all equal)
Unmarshal/SimpleDocument/struct-32 9.00 ± 0% 9.00 ± 0% ~ (all equal)
Unmarshal/SimpleDocument/map-32 13.0 ± 0% 13.0 ± 0% ~ (all equal)
Unmarshal/ReferenceFile/struct-32 183 ± 0% 183 ± 0% ~ (all equal)
Unmarshal/ReferenceFile/map-32 642 ± 0% 642 ± 0% ~ (all equal)
Unmarshal/HugoFrontMatter-32 141 ± 0% 141 ± 0% ~ (all equal)
```
Fixes #807
2022-08-20 21:24:03 -04:00
Thomas Pelletier
7baa23f493
Decode: error on array table mismatched type ( #804 )
...
Prevent the decoder from continuing if it encounters a type it cannot decode an
array table into.
Fixes #799
2022-08-15 16:38:07 -04:00
Thomas Pelletier
fb6d1d6c2b
Marshal: define and fix newlines behavior when using omitempty ( #798 )
...
Ref #786
2022-07-24 15:40:20 -04:00
Thomas Pelletier
627dade0c7
Encode: support comment on array tables ( #776 )
...
Fixes #774
2022-05-10 15:17:36 +02:00
Thomas Pelletier
c5ca2c682b
Fix embedded struct with explicit field name ( #773 )
...
Fixes #772
2022-05-09 18:45:02 +02:00
Thomas Pelletier
8bbb673431
Fuzzing setup and fixes ( #755 )
...
* encode: fix localdate formatting
* encode: fix empty key marshaling
* encode: fix invalid quotation of time.Time
* encode: ensure control chars are escaped
* decode: always use UTC for zero tz
* encode: check for invalid characters in keys
* encode: always construct map for empty array tables
* fuzz: add go 1.18 fuzz test
* encode: handle NaNs
* encode: allow new lines in quoted keys
* encode: never emit table inside array
* encode: don't capitalize inf
2022-04-10 21:37:12 -04:00
Thomas Pelletier
89d7b412d8
decode: allow subtables to be defined later ( #750 )
...
Fixes #739
2022-04-07 21:49:16 -04:00
Cameron Moore
146f70ea8a
Decode: use cleaned byte slice throughout parseFloat ( #735 )
...
Fixes #734
2022-01-06 14:34:27 -05:00
Thomas Pelletier
e83cf535f5
Decoder: rename SetStrict to DisallowUnknownFields ( #731 )
2022-01-02 14:32:34 -05:00
Cameron Moore
128b7a8bfb
Decode: check buffer length before parsing simple key ( #717 )
...
Fixes #714
2021-12-29 08:58:42 -05:00
Cameron Moore
892df5c28e
Decode: fix index out of range bug ( #716 )
...
Fixes #715
2021-12-29 08:49:33 -05:00
Thomas Pelletier
8ce5c3d78f
Decoder: time allows extra precision ( #710 )
...
As discussed[1], this change allows times to provide precision beyond the
nanosecond (nine digits fractional part). Extra precision is truncated according
to the TOML specificiation.
[1]: https://github.com/pelletier/go-toml/discussions/707
2021-12-26 17:05:10 +01:00
Thomas Pelletier
177b4a5e53
Decode: allow \r\n as line whitespace before \ ( #709 )
...
Fixes #708
2021-12-26 16:38:15 +01:00
Cameron Moore
5cbdea6192
decode: fix maximum time offset values ( #706 )
...
According to RFC3339 section 5.6, the maximum time offset values for
hours and minutes is 23 and 59, respectively.
2021-12-22 10:29:52 +01:00
Thomas Pelletier
696dd25c17
Decoder: disallow modification of existing table ( #704 )
...
Fixes #703
2021-12-15 11:05:27 -05:00
Thomas Pelletier
facb2b13e8
Decoder: prevent modification of inline tables ( #702 )
...
Fixes #701
2021-12-12 09:43:42 -05:00
Cameron Moore
8bbb519477
Decode: ensure signed exponents don't start with an underscore ( #699 )
2021-12-05 20:02:19 -05:00
Cameron Moore
b37e11d74d
Decode: allow maximum seconds value of 60 ( #700 )
...
RFC3339 allows seconds to be 60 when adding leap seconds
2021-12-05 20:00:42 -05:00
Cameron Moore
6cd86876b8
Decode: ensure signed numbers don't start with an underscore ( #698 )
2021-12-04 16:56:48 -05:00
Cameron Moore
f53bc740c1
Decode: restrict timezone offset values ( #696 )
...
Don't allow hours greater than 24 and minutes greater than 60 per RFC
3339.
2021-12-02 18:59:32 -05:00
Thomas Pelletier
9bf9be681e
Decoder: check for invalid chars in timezone ( #695 )
...
Fixes #694
2021-12-02 09:00:20 -05:00
Thomas Pelletier
c862c344b3
Decoder: allow commas in tags ( #693 )
2021-11-30 21:59:22 -05:00
Thomas Pelletier
3990899d7e
Decoder: check tz has : between hours and minutes ( #691 )
...
Fixes #690
2021-11-30 20:22:11 -05:00
Cameron Moore
4c7a337083
Decoder: fix typo in test description ( #689 )
2021-11-30 15:28:01 -05:00
Thomas Pelletier
bbaae540ce
Decoder: check timezones start with +,-,z,Z ( #688 )
...
Also simplifies local time seconds scanning.
Fixes #686
2021-11-30 13:01:15 -05:00
Thomas Pelletier
ede6445608
Decoder: flag bad \r in literal multiline strings ( #687 )
...
Fixes #685
2021-11-30 10:44:48 -05:00
Thomas Pelletier
b226db6a29
Decoder: show struct field in type mismatch errors ( #684 )
...
The goal is to provide some context as to why the type were mismatched. This
change only works for that case, on structs. This is the same a encoding/json. A
more general solution would be great, but this would require a broader change in
the decoder, which I don't think is necessary at the moment.
Fixes #628
2021-11-24 20:43:56 -05:00
Thomas Pelletier
79e78b234c
Decoder: fix panic on table array behind a pointer ( #682 )
...
Fixes #677
2021-11-24 18:50:04 -05:00
Thomas Pelletier
1b5a25c0ef
Decoder: fail on unescaped \r not followed by \n ( #681 )
...
Fixes #674
2021-11-24 18:11:36 -05:00
Thomas Pelletier
8eae15b2ee
Decoder: validate bounds of day and month in dates ( #680 )
...
Fixes #676
2021-11-24 17:42:01 -05:00
Thomas Pelletier
2b3de620e8
Encoder: try to use pointer type TextMarshaler ( #679 )
...
If a type does not implement the encoding.TextMarshaler interface but
its pointer type does, use it if possible.
Fixes #678
2021-11-24 14:43:49 -05:00
Cameron Moore
8645d6376b
Decoder: flag invalid carriage returns in literal strings ( #673 )
2021-11-23 22:41:59 -05:00
Thomas Pelletier
4dff8eaa4d
Decoder: prevent duplicates of inline tables ( #667 )
...
* seen: prevent duplicates of inline tables
* Provide clearer error message for redefined keys
For example:
``
toml: key b is already defined
```
2021-11-10 10:04:43 -05:00
Cameron Moore
2dbd29a565
parser: Fix missing check for upper exponent ( #665 )
2021-11-09 21:15:23 -05:00
Thomas Pelletier
f27a07d31a
seen: verify arrays ( #663 )
...
Fixes #662
2021-11-09 20:26:30 -05:00
Thomas Pelletier
8683be35f6
seen: check inline tables ( #660 )
...
Fixes #658
2021-11-08 21:53:02 -05:00
Thomas Pelletier
dc1740d473
Decode: code cleanup for struct cache ( #659 )
2021-11-07 18:35:30 -05:00
Thomas Pelletier
11f789ef11
Decode: prevent comments that look like dates to be accepted ( #657 )
...
* parser: fix date detection
When the parser has to decide between parsing and integer or a date, it should
check that all characters are actually acceptable (digits, or date/time
elements).
Fixes #655
2021-11-04 22:06:12 -04:00
Thomas Pelletier
74d21b367f
scanner: handle carriage return in comments ( #656 )
...
Fixes #653
2021-11-04 21:40:16 -04:00
Thomas Pelletier
3dbca20bc9
Decoder: flag invalid carriage returns in strings ( #652 )
...
Fixes #651
2021-11-02 10:02:25 -04:00
Thomas Pelletier
85c0658984
Decode: add missing checks for LocalTime ( #650 )
2021-10-29 22:13:08 -04:00
Thomas Pelletier
3694ae88f6
decode: error on _ before exponent in floats ( #647 )
...
Fixes #646
2021-10-28 20:41:10 -04:00
Thomas Pelletier
c871a61015
unmarshal: use UnmarshalText for any type ( #642 )
...
Not only structs can implement TextUnmarshaler.
Fixes #564
2021-10-28 17:02:47 -04:00
Thomas Pelletier
d0d001625c
unmarshal: don't panic when storing table in slice ( #641 )
...
New error message:
```
toml: cannot store a table in a slice
1| [things]
| ~~~~~~ cannot store a table in a slice
2| foo = "bar"
```
Fixes #623
2021-10-25 16:47:10 -04:00
Thomas Pelletier
64941b99e2
unmarshal: empty document results in map ( #640 )
...
Fixes #602
2021-10-25 15:55:54 -04:00
Thomas Pelletier
4d7c9ddac7
Floats and integers parsing fixes ( #638 )
...
* parser: fix scan of float with exp but no decimal
* decoder: validate leading zeros for decimals
2021-10-22 22:25:56 -04:00
Cameron Moore
a23850f29b
decode: preserve nanosecond precision when decoding time ( #626 )
...
Co-authored-by: Thomas Pelletier <thomas@pelletier.codes >
2021-10-17 20:43:29 -04:00