dependabot-hex 0.118.16 → 0.119.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 966641c97b9444eb8970f7c71a823145222ac31a91908f850757e1f8c66a4074
4
- data.tar.gz: 51c261247173648cb33ec489d020f3b1b734317044a0f803cdb219f32544fc0a
3
+ metadata.gz: 3604a148074d38433c48025d48dbc44da12cd64132cfd55372445b47dd830864
4
+ data.tar.gz: db60087432ed4e23f7edc0014348bb47175ca81fa5cdd1b1811936c747c0f260
5
5
  SHA512:
6
- metadata.gz: 20d4406f524c498fc57fab05d8e6da910d115114721a49882c3c0ffb271c027413d178e82abd4514d6e5ef727eb5e06d15014d7ab18c3dbd5862dce05bcba0e0
7
- data.tar.gz: 6674fa19ead51028acf8ed3617854793d42cbf920d6392a8ef8d2c47f8010e7feaa9f7bf897675a6fede2ba61dadc1f419a0e5614b8e3ec2f701c2ce0295f554
6
+ metadata.gz: 4cc9b3bafe4314ea6147a566e4c99ba1f5ef9d53d8428fa50cf0bdd70736dc996b7c3e16d4e7c5869224504632d850ebe69f85fa4037a4b961633d9b8a2b5f4d
7
+ data.tar.gz: 549c1b9f72347c16f9bfbde5137e1ddf92a163283f0c016ea331867efa41e0ec64a4669074a6c4fd872235063b8621958b68980c3d7686a0d7ca68a8e4b7fa2c
File without changes
@@ -0,0 +1,88 @@
1
+ # Changelog
2
+
3
+ ## 1.2.1 (04.05.2020)
4
+
5
+ ### Security
6
+
7
+ * Fix `html_safe` escaping in `Jason.encode`
8
+
9
+ The `<!--` sequence of characters would not be escaped in `Jason.encode`
10
+ with`html_escape` mode, which could lead to DoS attacks when used for
11
+ embedding of arbitrary, user controlled strings into HTML through JSON
12
+ (e.g. inside of `<script>` tags).
13
+
14
+ If you were not using the `html_safe` option, you are not affected.
15
+
16
+ Affected versions: < 1.2.1
17
+ Patched versions: >= 1.2.1
18
+
19
+ ## 1.2.0 (17.03.2020)
20
+
21
+ ### Enhancements
22
+
23
+ * Add `Jason.Encode.keyword/2`
24
+ ([cb1f26a](https://github.com/michalmuskala/jason/commit/cb1f26a)).
25
+
26
+ ### Bug fixes
27
+
28
+ * Fix `Jason.Helpers.json_map/1` value expansion
29
+ ([70b046a](https://github.com/michalmuskala/jason/commit/70b046a)).
30
+
31
+ ## 1.1.2 (19.10.2018)
32
+
33
+ ### Bug fixes
34
+
35
+ * correctly handle the `pretty: false` option
36
+ ([ba318c8](https://github.com/michalmuskala/jason/commit/ba318c8)).
37
+
38
+ ## 1.1.1 (10.07.2018)
39
+
40
+ ### Bug fixes
41
+
42
+ * correctly handle escape sequences in strings when pretty printing
43
+ ([794bbe4](https://github.com/michalmuskala/jason/commit/794bbe4)).
44
+
45
+ ## 1.1.0 (02.07.2018)
46
+
47
+ ### Enhancements
48
+
49
+ * pretty-printing support through `Jason.Formatter` and `pretty: true` option
50
+ in `Jason.encode/2` ([d758e36](https://github.com/michalmuskala/jason/commit/d758e36)).
51
+
52
+ ### Bug fixes
53
+
54
+ * silence variable warnings for fields with underscores used during deriving
55
+ ([88dd85c](https://github.com/michalmuskala/jason/commit/88dd85c)).
56
+ * **potential incompatibility** don't raise `Protocol.UndefinedError` in non-bang functions
57
+ ([ad0f57b](https://github.com/michalmuskala/jason/commit/ad0f57b)).
58
+
59
+ ## 1.0.1 (02.07.2018)
60
+
61
+ ### Bug fixes
62
+
63
+ * fix `Jason.Encode.escape` type ([a57b430](https://github.com/michalmuskala/jason/commit/a57b430))
64
+ * multiple documentation improvements
65
+
66
+ ## 1.0.0 (26.01.2018)
67
+
68
+ No changes
69
+
70
+ ## 1.0.0-rc.3 (26.01.2018)
71
+
72
+ ### Changes
73
+
74
+ * update `escape` option of `Jason.encode/2` to take values:
75
+ `:json | :unicode_safe | :html_safe | :javascript_safe` for consistency. Old values of
76
+ `:unicode` and `:javascript` are still supported for compatibility with Poison.
77
+ ([f42dcbd](https://github.com/michalmuskala/jason/commit/f42dcbd))
78
+
79
+ ## 1.0.0-rc.2 (07.01.2018)
80
+
81
+ ### Bug fixes
82
+
83
+ * add type for `strings` option ([b459ee4](https://github.com/michalmuskala/jason/commit/b459ee4))
84
+ * support iodata in `decode!` ([a1f3456](https://github.com/michalmuskala/jason/commit/a1f3456))
85
+
86
+ ## 1.0.0-rc.1 (22.12.2017)
87
+
88
+ Initial release
@@ -0,0 +1,13 @@
1
+ Copyright 2017 Michał Muskała
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,141 @@
1
+ # Jason
2
+
3
+ A blazing fast JSON parser and generator in pure Elixir.
4
+
5
+ The parser and generator are at least twice as fast as other Elixir/Erlang libraries
6
+ (most notably `Poison`).
7
+ The performance is comparable to `jiffy`, which is implemented in C as a NIF.
8
+ Jason is usually only twice as slow.
9
+
10
+ Both parser and generator fully conform to
11
+ [RFC 8259](https://tools.ietf.org/html/rfc8259) and
12
+ [ECMA 404](http://www.ecma-international.org/publications/standards/Ecma-404.htm)
13
+ standards. The parser is tested using [JSONTestSuite](https://github.com/nst/JSONTestSuite).
14
+
15
+ ## Installation
16
+
17
+ The package can be installed by adding `jason` to your list of dependencies
18
+ in `mix.exs`:
19
+
20
+ ```elixir
21
+ def deps do
22
+ [{:jason, "~> 1.2"}]
23
+ end
24
+ ```
25
+
26
+ ## Basic Usage
27
+
28
+ ``` elixir
29
+ iex(1)> Jason.encode!(%{"age" => 44, "name" => "Steve Irwin", "nationality" => "Australian"})
30
+ "{\"age\":44,\"name\":\"Steve Irwin\",\"nationality\":\"Australian\"}"
31
+
32
+ iex(2)> Jason.decode!(~s({"age":44,"name":"Steve Irwin","nationality":"Australian"}))
33
+ %{"age" => 44, "name" => "Steve Irwin", "nationality" => "Australian"}
34
+ ```
35
+
36
+ Full documentation can be found at [https://hexdocs.pm/jason](https://hexdocs.pm/jason).
37
+
38
+ ## Use with other libraries
39
+
40
+ ### Postgrex
41
+
42
+ Versions starting at 0.14.0 use `Jason` by default. For earlier versions, please refer to
43
+ [previous versions of this document](https://github.com/michalmuskala/jason/tree/v1.1.2#postgrex).
44
+
45
+ ### Ecto
46
+
47
+ Versions starting at 3.0.0 use `Jason` by default. For earlier versions, please refer to
48
+ [previous versions of this document](https://github.com/michalmuskala/jason/tree/v1.1.2#ecto).
49
+
50
+ ### Plug (and Phoenix)
51
+
52
+ Phoenix starting at 1.4.0 uses `Jason` by default. For earlier versions, please refer to
53
+ [previous versions of this document](https://github.com/michalmuskala/jason/tree/v1.1.2#plug-and-phoenix).
54
+
55
+ ### Absinthe
56
+
57
+ You need to pass the `:json_codec` option to `Absinthe.Plug`
58
+
59
+ ```elixir
60
+ # When called directly:
61
+ plug Absinthe.Plug,
62
+ schema: MyApp.Schema,
63
+ json_codec: Jason
64
+
65
+ # When used in phoenix router:
66
+ forward "/api",
67
+ to: Absinthe.Plug,
68
+ init_opts: [schema: MyApp.Schema, json_codec: Jason]
69
+ ```
70
+
71
+ ## Benchmarks
72
+
73
+ Detailed benchmarks (including memory measurements):
74
+ https://gist.github.com/michalmuskala/4d64a5a7696ca84ac7c169a0206640d5
75
+
76
+ HTML reports for the benchmark (only performance measurements):
77
+ http://michal.muskala.eu/jason/decode.html and http://michal.muskala.eu/jason/encode.html
78
+
79
+ ### Running
80
+
81
+ Benchmarks against most popular Elixir & Erlang json libraries can be executed after
82
+ going into the `bench/` folder and then executing `mix bench.encode` and `mix bench.decode`.
83
+ A HTML report of the benchmarks (after their execution) can be found in
84
+ `bench/output/encode.html` and `bench/output/decode.html` respectively.
85
+
86
+ ## Differences to Poison
87
+
88
+ Jason has a couple feature differences compared to Poison.
89
+
90
+ * Jason follows the JSON spec more strictly, for example it does not allow
91
+ unescaped newline characters in JSON strings - e.g. `"\"\n\""` will
92
+ produce a decoding error.
93
+ * no support for decoding into data structures (the `as:` option).
94
+ * no built-in encoders for `MapSet`, `Range` and `Stream`.
95
+ * no support for encoding arbitrary structs - explicit implementation
96
+ of the `Jason.Encoder` protocol is always required.
97
+ * different pretty-printing customisation options (default `pretty: true` works the same)
98
+
99
+ If you require encoders for any of the unsupported collection types, I suggest
100
+ adding the needed implementations directly to your project:
101
+
102
+ ```elixir
103
+ defimpl Jason.Encoder, for: [MapSet, Range, Stream] do
104
+ def encode(struct, opts) do
105
+ Jason.Encode.list(Enum.to_list(struct), opts)
106
+ end
107
+ end
108
+ ```
109
+
110
+ If you need to encode some struct that does not implement the protocol,
111
+ if you own the struct, you can derive the implementation specifying
112
+ which fields should be encoded to JSON:
113
+
114
+ ```elixir
115
+ @derive {Jason.Encoder, only: [....]}
116
+ defstruct # ...
117
+ ```
118
+
119
+ It is also possible to encode all fields, although this should be
120
+ used carefully to avoid accidentally leaking private information
121
+ when new fields are added:
122
+
123
+ ```elixir
124
+ @derive Jason.Encoder
125
+ defstruct # ...
126
+ ```
127
+
128
+ Finally, if you don't own the struct you want to encode to JSON,
129
+ you may use `Protocol.derive/3` placed outside of any module:
130
+
131
+ ```elixir
132
+ Protocol.derive(Jason.Encoder, NameOfTheStruct, only: [...])
133
+ Protocol.derive(Jason.Encoder, NameOfTheStruct)
134
+ ```
135
+
136
+ ## License
137
+
138
+ Jason is released under the Apache License 2.0 - see the [LICENSE](LICENSE) file.
139
+
140
+ Some elements of tests and benchmarks have their origins in the
141
+ [Poison library](https://github.com/devinus/poison) and were initially licensed under [CC0-1.0](https://creativecommons.org/publicdomain/zero/1.0/).
@@ -0,0 +1,20 @@
1
+ {<<"app">>,<<"jason">>}.
2
+ {<<"build_tools">>,[<<"mix">>]}.
3
+ {<<"description">>,
4
+ <<"A blazing fast JSON parser and generator in pure Elixir.">>}.
5
+ {<<"elixir">>,<<"~> 1.4">>}.
6
+ {<<"files">>,
7
+ [<<"lib">>,<<"lib/jason.ex">>,<<"lib/encoder.ex">>,<<"lib/decoder.ex">>,
8
+ <<"lib/formatter.ex">>,<<"lib/encode.ex">>,<<"lib/codegen.ex">>,
9
+ <<"lib/helpers.ex">>,<<"lib/fragment.ex">>,<<"mix.exs">>,<<"README.md">>,
10
+ <<"LICENSE">>,<<"CHANGELOG.md">>]}.
11
+ {<<"licenses">>,[<<"Apache-2.0">>]}.
12
+ {<<"links">>,[{<<"GitHub">>,<<"https://github.com/michalmuskala/jason">>}]}.
13
+ {<<"name">>,<<"jason">>}.
14
+ {<<"requirements">>,
15
+ [[{<<"app">>,<<"decimal">>},
16
+ {<<"name">>,<<"decimal">>},
17
+ {<<"optional">>,true},
18
+ {<<"repository">>,<<"hexpm">>},
19
+ {<<"requirement">>,<<"~> 1.0">>}]]}.
20
+ {<<"version">>,<<"1.2.1">>}.
@@ -0,0 +1,138 @@
1
+ defmodule Jason.Codegen do
2
+ @moduledoc false
3
+
4
+ alias Jason.{Encode, EncodeError}
5
+
6
+ def jump_table(ranges, default) do
7
+ ranges
8
+ |> ranges_to_orddict()
9
+ |> :array.from_orddict(default)
10
+ |> :array.to_orddict()
11
+ end
12
+
13
+ def jump_table(ranges, default, max) do
14
+ ranges
15
+ |> ranges_to_orddict()
16
+ |> :array.from_orddict(default)
17
+ |> resize(max)
18
+ |> :array.to_orddict()
19
+ end
20
+
21
+ defmacro bytecase(var, do: clauses) do
22
+ {ranges, default, literals} = clauses_to_ranges(clauses, [])
23
+
24
+ jump_table = jump_table(ranges, default)
25
+
26
+ quote do
27
+ case unquote(var) do
28
+ unquote(jump_table_to_clauses(jump_table, literals))
29
+ end
30
+ end
31
+ end
32
+
33
+ defmacro bytecase(var, max, do: clauses) do
34
+ {ranges, default, empty} = clauses_to_ranges(clauses, [])
35
+
36
+ jump_table = jump_table(ranges, default, max)
37
+
38
+ quote do
39
+ case unquote(var) do
40
+ unquote(jump_table_to_clauses(jump_table, empty))
41
+ end
42
+ end
43
+ end
44
+
45
+ def build_kv_iodata(kv, encode_args) do
46
+ elements =
47
+ kv
48
+ |> Enum.map(&encode_pair(&1, encode_args))
49
+ |> Enum.intersperse(",")
50
+
51
+ collapse_static(List.flatten(["{", elements] ++ '}'))
52
+ end
53
+
54
+ defp clauses_to_ranges([{:->, _, [[{:in, _, [byte, range]}, rest], action]} | tail], acc) do
55
+ clauses_to_ranges(tail, [{range, {byte, rest, action}} | acc])
56
+ end
57
+
58
+ defp clauses_to_ranges([{:->, _, [[default, rest], action]} | tail], acc) do
59
+ {Enum.reverse(acc), {default, rest, action}, literal_clauses(tail)}
60
+ end
61
+
62
+ defp literal_clauses(clauses) do
63
+ Enum.map(clauses, fn {:->, _, [[literal], action]} ->
64
+ {literal, action}
65
+ end)
66
+ end
67
+
68
+ defp jump_table_to_clauses([{val, {{:_, _, _}, rest, action}} | tail], empty) do
69
+ quote do
70
+ <<unquote(val), unquote(rest)::bits>> ->
71
+ unquote(action)
72
+ end ++ jump_table_to_clauses(tail, empty)
73
+ end
74
+
75
+ defp jump_table_to_clauses([{val, {byte, rest, action}} | tail], empty) do
76
+ quote do
77
+ <<unquote(byte), unquote(rest)::bits>> when unquote(byte) === unquote(val) ->
78
+ unquote(action)
79
+ end ++ jump_table_to_clauses(tail, empty)
80
+ end
81
+
82
+ defp jump_table_to_clauses([], literals) do
83
+ Enum.flat_map(literals, fn {pattern, action} ->
84
+ quote do
85
+ unquote(pattern) ->
86
+ unquote(action)
87
+ end
88
+ end)
89
+ end
90
+
91
+ defp resize(array, size), do: :array.resize(size, array)
92
+
93
+ defp ranges_to_orddict(ranges) do
94
+ ranges
95
+ |> Enum.flat_map(fn
96
+ {int, value} when is_integer(int) ->
97
+ [{int, value}]
98
+
99
+ {enum, value} ->
100
+ Enum.map(enum, &{&1, value})
101
+ end)
102
+ |> :orddict.from_list()
103
+ end
104
+
105
+ defp encode_pair({key, value}, encode_args) do
106
+ key = IO.iodata_to_binary(Encode.key(key, &escape_key/3))
107
+ key = "\"" <> key <> "\":"
108
+ [key, quote(do: Encode.value(unquote(value), unquote_splicing(encode_args)))]
109
+ end
110
+
111
+ defp escape_key(binary, _original, _skip) do
112
+ check_safe_key!(binary)
113
+ binary
114
+ end
115
+
116
+ defp check_safe_key!(binary) do
117
+ for <<(<<byte>> <- binary)>> do
118
+ if byte > 0x7F or byte < 0x1F or byte in '"\\/' do
119
+ raise EncodeError,
120
+ "invalid byte #{inspect(byte, base: :hex)} in literal key: #{inspect(binary)}"
121
+ end
122
+ end
123
+
124
+ :ok
125
+ end
126
+
127
+ defp collapse_static([bin1, bin2 | rest]) when is_binary(bin1) and is_binary(bin2) do
128
+ collapse_static([bin1 <> bin2 | rest])
129
+ end
130
+
131
+ defp collapse_static([other | rest]) do
132
+ [other | collapse_static(rest)]
133
+ end
134
+
135
+ defp collapse_static([]) do
136
+ []
137
+ end
138
+ end