Commit graph

109 commits

Author SHA1 Message Date
Benoit Daloze
9c4a28b826 [flori/json] Use the pure-Ruby generator on TruffleRuby as it is much faster
* Using the benchmark from https://github.com/flori/json/pull/580
$ ruby benchmarks/bench.rb dump pure
JSON::Pure::Generator
truffleruby 24.0.0, like ruby 3.2.2, Oracle GraalVM Native [x86_64-linux]
Warming up --------------------------------------
      JSON.dump(obj)   116.000 i/100ms
      JSON.dump(obj)   235.000 i/100ms
      JSON.dump(obj)   317.000 i/100ms
      JSON.dump(obj)   372.000 i/100ms
      JSON.dump(obj)   374.000 i/100ms
Calculating -------------------------------------
      JSON.dump(obj)      3.735k (± 0.9%) i/s  (267.76 μs/i) -     18.700k in   5.007526s
      JSON.dump(obj)      3.738k (± 0.7%) i/s  (267.49 μs/i) -     18.700k in   5.002252s
      JSON.dump(obj)      3.743k (± 0.7%) i/s  (267.18 μs/i) -     19.074k in   5.096375s
      JSON.dump(obj)      3.747k (± 0.5%) i/s  (266.87 μs/i) -     19.074k in   5.090463s
      JSON.dump(obj)      3.746k (± 0.5%) i/s  (266.96 μs/i) -     19.074k in   5.092069s
$ ruby benchmarks/bench.rb dump ext
JSON::Ext::Generator
truffleruby 24.0.0, like ruby 3.2.2, Oracle GraalVM Native [x86_64-linux]
Warming up --------------------------------------
      JSON.dump(obj)    19.000 i/100ms
      JSON.dump(obj)    18.000 i/100ms
      JSON.dump(obj)    18.000 i/100ms
      JSON.dump(obj)    18.000 i/100ms
      JSON.dump(obj)    21.000 i/100ms
Calculating -------------------------------------
      JSON.dump(obj)    221.260 (±10.8%) i/s    (4.52 ms/i) -      1.092k in   5.004381s
      JSON.dump(obj)    221.983 (± 8.1%) i/s    (4.50 ms/i) -      1.113k in   5.055574s
      JSON.dump(obj)    221.446 (± 8.6%) i/s    (4.52 ms/i) -      1.113k in   5.073167s
      JSON.dump(obj)    226.452 (± 7.9%) i/s    (4.42 ms/i) -      1.134k in   5.048568s
      JSON.dump(obj)    227.795 (± 8.3%) i/s    (4.39 ms/i) -      1.134k in   5.025187s

8256455cdc
2024-06-04 14:44:43 +09:00
Hiroshi SHIBATA
ab65148c78 [flori/json] Bump up 2.7.2
036944acc6
2024-04-04 12:46:02 +09:00
Hiroshi SHIBATA
514b415d90 [flori/json] Warn to install ostruct if json couldn't load it
fff285968d
2024-04-04 12:46:02 +09:00
tompng
066bd28cff [flori/json] Autoload GenericObject to avoid require ostruct warning in Ruby 3.4
b507f9e404
2024-04-04 12:46:01 +09:00
Hiroshi SHIBATA
7c8f9603b1 [flori/json] Make OpenStruct support as optional
202ffe2335
2024-01-31 14:56:00 +09:00
Hiroshi SHIBATA
eecae51502 [flori/json] Bump up 2.7.1
a1af7a308c
2023-12-05 15:09:56 +09:00
Burdette Lamar
c8faaf4c7e [flori/json] [DOC] RDoc for additions
(https://github.com/flori/json/pull/557)

* RDoc for additions

* Update lib/json/add/time.rb

Co-authored-by: Hiroshi SHIBATA <hsbt@ruby-lang.org>

---------

3f2efd60f7

Co-authored-by: Hiroshi SHIBATA <hsbt@ruby-lang.org>
2023-12-05 12:04:09 +09:00
tompng
70740deea7 [flori/json] Fix JSON.dump overload combination
41c2712a3b
2023-12-05 12:04:08 +09:00
Takashi Kokubun
e6b35e8a6d [flori/json] Overload kwargs in JSON.dump
936f280f9f
2023-12-05 12:04:08 +09:00
Jean Boussier
a22ed89438 [flori/json] JSON.dump: handle unenclosed hashes regression
Fix: https://github.com/flori/json/issues/553

We can never add keyword arguments to `dump` otherwise
existing code using unenclosed hash will break.

8e0076a3f2
2023-12-05 12:04:07 +09:00
Hiroshi SHIBATA
86045fca24
Manually merged from flori/json
> https://github.com/flori/json/pull/525
  > Rename escape_slash in script_safe and also escape E+2028 and E+2029

  Co-authored-by: Jean Boussier <jean.boussier@gmail.com>

  > https://github.com/flori/json/pull/454
  > Remove unnecessary initialization of create_id in JSON.parse()

  Co-authored-by: Watson <watson1978@gmail.com>
2023-12-01 16:47:06 +09:00
Jean Boussier
0dfeb17296
Rename escape_slash in script_safe and also escape E+2028 and E+2029
It is rather common to directly interpolate JSON string inside
<script> tags in HTML as to provide configuration or parameters to a
script.

However this may lead to XSS vulnerabilities, to prevent that 3
characters need to be escaped:

  - `/` (forward slash)
  - `U+2028` (LINE SEPARATOR)
  - `U+2029` (PARAGRAPH SEPARATOR)

The forward slash need to be escaped to prevent closing the script
tag early, and the other two are valid JSON but invalid Javascript
and can be used to break JS parsing.

Given that the intent of escaping forward slash is the same than escaping
U+2028 and U+2029, I chos to rename and repurpose the existing `escape_slash`
option.
2023-12-01 16:47:06 +09:00
Hiroshi SHIBATA
32f289d118
[flori/json] Bump up 2.7.0
ca546128f2
2023-12-01 16:47:06 +09:00
BurdetteLamar
d12e881009
[flori/json] Enhanced RDoc for Range extensions
ec47749b53
2023-11-08 09:04:28 +09:00
Nobuyoshi Nakada
768668a4de [flori/json] Remove unnecessary code
In `JSON#generate` and `JSON#fast_generate`:

- When the given `opts` is a `JSON::State` the variable is set to
  `nil`.
- But it will be never used as the next `if` blocks will not be
  executed.
- `JSON::State#configure` does the conversion to `Hash`, the
  conversions in the `if` block are just duplication.
- `JSON::State.new` does the same thing with `configure` when an
  argument is given.

5d9ab87f8e
2023-07-19 00:02:58 +09:00
Hiroshi SHIBATA
56c8dab468 [flori/json] Skip BigDecimal tests when it's missing to load
3dd36c6077
2023-07-18 12:25:55 +09:00
Hiroshi SHIBATA
3b45498d3e Merge json-2.6.3 2022-12-09 16:36:22 +09:00
Florian Frank
9245b28d34
[flori/json] Bump version to 2.6.2
5de358f655
2022-05-20 17:49:13 +09:00
Hiroshi SHIBATA
1be2875e1d
[flori/json] Bump version to v2.6.1
2db5894cfa
2021-10-24 09:25:20 +09:00
Josef Šimánek
4cbce79438
[flori/json] Bump JSON::VERSION to 2.6.0.
da94d9f059
2021-10-24 09:25:01 +09:00
Masafumi Koba
8a974dc83c [flori/json] Fix incorrect # position in API doc
This change fixes an incorrect `#` position in the API documentation of the `JSON` module.

dc4b62424f
2021-05-17 19:26:03 +09:00
Hiroshi SHIBATA
034c19ce28
Merge json-2.5.1 2020-12-22 21:51:15 +09:00
Hiroshi SHIBATA
edb76e8765 Prepare to release json-2.5.0 2020-12-22 19:44:27 +09:00
Kenta Murata
0b6a80c0be
[json] Avoid method redefinition 2020-12-21 22:41:24 +09:00
Kenta Murata
596da98b3f
[json] Make JSON.create_id thread-safe 2020-12-21 22:10:42 +09:00
Kenta Murata
98cc15ed1e
[json] Stop using prototype objects 2020-12-21 22:10:33 +09:00
Hiroshi SHIBATA
46ea74297e
Bump version to json-2.4.1 and use VERSION file for json version same as upstream 2020-12-17 14:20:42 +09:00
Hiroshi SHIBATA
17e7a819f7 Complex and Rational is embedded classes now 2020-11-10 13:14:42 +09:00
Jean Boussier
927a377a7c [flori/json] Fix JSON.load_file doc
cb61a00ba8
2020-09-25 17:28:42 +09:00
BurdetteLamar
038252fe66 [flori/json] Partial compliance with doc/method_documentation.rdoc
6dfa885134
2020-09-25 17:28:42 +09:00
Burdette Lamar
71f64e15b9 [flori/json] Enhanced RDoc for JSON.dump (#443)
* Enhanced RDoc for JSON.dump
03f1699ec4
2020-09-25 17:28:42 +09:00
BurdetteLamar
de0e0ffad4 [flori/json] Nodoc for recurse_proc
f8c0fe2408
2020-09-25 17:28:42 +09:00
BurdetteLamar
e9096f796c [flori/json] RDoc for JSON.load with proc
a55c91934e
2020-09-25 17:28:42 +09:00
BurdetteLamar
8c057bb845 [flori/json] RDoc example for JSON.load
e4eead665c
2020-09-25 17:28:42 +09:00
BurdetteLamar
36b2177ea8 [flori/json] Enhance RDoc for JSON.parse
33e64ef255
2020-09-25 17:28:42 +09:00
BurdetteLamar
71b1bbad02 [flori/json] Move options from #generate and #parse to common area
20d7be605a
2020-09-25 17:28:42 +09:00
Keith Bennett
c3614877d2 [flori/json] Add load_file and load_file! methods, with tests. Fixes issue #386.
0be363c99b
2020-09-25 17:28:42 +09:00
Jean Boussier
e1659af372 Add an option to escape forward slash character
Squashed commit of the following:

commit 26d181059989279a79c433cedcd893b4f52e42ee
Author: Francois Chagnon <francois.chagnon@jadedpixel.com>
Date:   Tue Sep 15 21:17:34 2015 +0000

    add config options for escape_slash

commit fa282334051b16df91ca097dd7304b46f3bc7719
Author: Francois Chagnon <francois.chagnon@jadedpixel.com>
Date:   Mon Feb 9 21:09:33 2015 +0000

    add forward slash to escape character
2020-09-25 17:28:42 +09:00
Hiroshi SHIBATA
0aac138e0b
Merge json-2.3.1 from flori/json 2020-07-01 18:50:39 +09:00
BurdetteLamar
d69b55ac05
[flori/json] Added :call-seq: to RDOc for some methods
ee5b6a74e9
2020-07-01 18:47:51 +09:00
BurdetteLamar
7d8ce96de6
[flori/json] RDoc enhancements
ada48f0236
2020-07-01 18:47:51 +09:00
BurdetteLamar
be6447381c
[flori/json] RDoc enhancements
470d909c0d
2020-07-01 18:47:51 +09:00
BurdetteLamar
99980b3034
[flori/json] RDoc enhancements
7bee2c7c13
2020-07-01 18:47:51 +09:00
BurdetteLamar
4689fd5f99
[flori/json] Rdoc enhancements
e7e3732130
2020-07-01 18:47:50 +09:00
zverok
41ef6df8c9 [flori/json] Fix examples syntax
3845491d92
2020-01-06 15:13:35 +09:00
zverok
2e5ef30cb9 [flori/json] Enchance generic JSON and #generate docs
4ede0a7d19
2020-01-06 15:13:15 +09:00
Jeremy Evans
1658e6b5db
[flori/json] Remove invalid JSON.generate description from JSON module rdoc
This text used to be true in older versions of json, but has not
been true for a number of years (since json version 2 I think).

373b633f38
2020-01-06 15:09:55 +09:00
Hiroshi SHIBATA
53e8589c69
Import json-2.3.0 from flori/json 2019-12-12 09:14:09 +09:00
Sho Hashimoto
d9e50fcbeb
[flori/json] Pass args all #to_json in json/add/*.
36a7ef6790
2019-10-14 19:54:48 +09:00
Jeremy Evans
80b5a0ff2a
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.

This makes the following changes to : handling.

* Treats as **kw, prompting keyword argument separation warnings
  if called with a positional hash.

* Do not look for an option hash if empty keywords are provided.
  For backwards compatibility, treat an empty keyword splat as a empty
  mandatory positional hash argument, but emit a a warning, as this
  behavior will be removed in Ruby 3.  The argument number check
  needs to be moved lower so it can correctly handle an empty
  positional argument being added.

* If the last argument is nil and it is necessary to treat it as an option
  hash in order to make sure all arguments are processed, continue to
  treat the last argument as the option hash. Emit a warning in this case,
  as this behavior will be removed in Ruby 3.

* If splitting the keyword hash into two hashes, issue a warning, as we
  will not be splitting hashes in Ruby 3.

* If the keyword argument is required to fill a mandatory positional
  argument, continue to do so, but emit a warning as this behavior will
  be going away in Ruby 3.

* If keyword arguments are provided and the last argument is not a hash,
  that indicates something wrong. This can happen if a cfunc is calling
  rb_scan_args multiple times, and providing arguments that were not
  passed to it from Ruby.  Callers need to switch to the new
  rb_scan_args_kw function, which allows passing of whether keywords
  were provided.

This commit fixes all warnings caused by the changes above.

It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used.  If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.

In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby.  The last argument may or may not be a hash,
so we can't set keyword argument mode.  However, if it is a
hash, we don't want to warn when treating it as keywords.

In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args.  Also, make
sure not to pass nil in place of an option hash.

Work around Kernel#warn warnings due to problems in the Rubygems
override of the method.  There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.

Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 11:18:49 -07:00