Skip to content

Commit 0cd25ba

Browse files
Add tests for rubygems package assembly
Reference: #5306 Signed-off-by: Ayan Sinha Mahapatra <asmahapatra@aboutcode.org>
1 parent 37b3e4b commit 0cd25ba

22 files changed

Lines changed: 4654 additions & 175 deletions

File tree

tests/packagedcode/data/rubygems/package/json-3.0.2-java.gem-extract.json

Lines changed: 479 additions & 0 deletions
Large diffs are not rendered by default.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
SHA256:
3+
metadata.gz: 4be775fd0d4221af4703313be47b36df730b542f95063025472d82386bc6f949
4+
data.tar.gz: aa1136bf72ebb55174ab30a3ddcaf908364a7e0cde743b952435a5ab59195d0a
5+
SHA512:
6+
metadata.gz: 3b1da37df8ae7d0a8a40e41caed988f2b9f33c8ef147e66220e811adbc26199482189055badf0023bc5c4b8f201f2954a30cfa355cd7629604485c0424869f06
7+
data.tar.gz: 7e50467d636c6a30b701d4778650355e6856660add1de37eef2519865977107e715cf19d3bcceff288ee068b5993908535243b6b799f7bc37bd7f41b8c270d37
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions
5+
are met:
6+
1. Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
2. Redistributions in binary form must reproduce the above copyright
9+
notice, this list of conditions and the following disclaimer in the
10+
documentation and/or other materials provided with the distribution.
11+
12+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22+
SUCH DAMAGE.

tests/packagedcode/data/rubygems/package/json-3.0.2-java.gem-extract/data.tar.gz-extract/CHANGES.md

Lines changed: 868 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2+
You can redistribute it and/or modify it under either the terms of the
3+
2-clause BSDL (see the file BSDL), or the conditions below:
4+
5+
1. You may make and give away verbatim copies of the source form of the
6+
software without restriction, provided that you duplicate all of the
7+
original copyright notices and associated disclaimers.
8+
9+
2. You may modify your copy of the software in any way, provided that
10+
you do at least ONE of the following:
11+
12+
a) place your modifications in the Public Domain or otherwise
13+
make them Freely Available, such as by posting said
14+
modifications to Usenet or an equivalent medium, or by allowing
15+
the author to include your modifications in the software.
16+
17+
b) use the modified software only within your corporation or
18+
organization.
19+
20+
c) give non-standard binaries non-standard names, with
21+
instructions on where to get the original software distribution.
22+
23+
d) make other distribution arrangements with the author.
24+
25+
3. You may distribute the software in object code or binary form,
26+
provided that you do at least ONE of the following:
27+
28+
a) distribute the binaries and library files of the software,
29+
together with instructions (in the manual page or equivalent)
30+
on where to get the original distribution.
31+
32+
b) accompany the distribution with the machine-readable source of
33+
the software.
34+
35+
c) give non-standard binaries non-standard names, with
36+
instructions on where to get the original software distribution.
37+
38+
d) make other distribution arrangements with the author.
39+
40+
4. You may modify and include the part of the software into any other
41+
software (possibly commercial). But some files in the distribution
42+
are not written by the author, so that they are not under these terms.
43+
44+
For the list of those files and their copying conditions, see the
45+
file LEGAL.
46+
47+
5. The scripts and library files supplied as input to or produced as
48+
output from the software do not automatically fall under the
49+
copyright of the software, but belong to whomever generated them,
50+
and may be sold commercially, and may be aggregated with this
51+
software.
52+
53+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56+
PURPOSE.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- rdoc -*-
2+
3+
= LEGAL NOTICE INFORMATION
4+
--------------------------
5+
6+
All the files in this distribution are covered under either the Ruby's
7+
license (see the file COPYING) or public-domain except some files
8+
mentioned below.
9+
10+
ext/json/ext/vendor/fpconv.h::
11+
This file is adapted from https://github.com/night-shift/fpconv
12+
It is licensed under Boost Software License 1.0.
13+
14+
ext/json/ext/vendor/jeaiii-ltoa.h::
15+
This file is adapted from https://github.com/jeaiii/itoa
16+
It is licensed under the MIT License
17+
18+
ext/json/ext/vendor/fast_float_parser.h::
19+
This file is adapted from the Fast Float C++ library by The fast_float authors https://github.com/fastfloat/fast_float
20+
It is licensed under the MIT License
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
# JSON implementation for Ruby
2+
3+
[![CI](https://github.com/ruby/json/actions/workflows/ci.yml/badge.svg)](https://github.com/ruby/json/actions/workflows/ci.yml)
4+
5+
## Description
6+
7+
This is an implementation of the JSON specification according to RFC 7159
8+
http://www.ietf.org/rfc/rfc7159.txt .
9+
10+
The JSON generator generate UTF-8 character sequences by default.
11+
If an :ascii\_only option with a true value is given, they escape all
12+
non-ASCII and control characters with \uXXXX escape sequences, and support
13+
UTF-16 surrogate pairs in order to be able to generate the whole range of
14+
unicode code points.
15+
16+
All strings, that are to be encoded as JSON strings, should be UTF-8 byte
17+
sequences on the Ruby side.
18+
19+
## Installation
20+
21+
Install the gem and add to the application's Gemfile by executing:
22+
23+
$ bundle add json
24+
25+
If bundler is not being used to manage dependencies, install the gem by executing:
26+
27+
$ gem install json
28+
29+
## Basic Usage
30+
31+
To use JSON you can
32+
33+
```ruby
34+
require 'json'
35+
```
36+
37+
Now you can parse a JSON document into a ruby data structure by calling
38+
39+
```ruby
40+
JSON.parse(document)
41+
```
42+
43+
If you want to generate a JSON document from a ruby data structure call
44+
```ruby
45+
JSON.generate(data)
46+
```
47+
48+
You can also use the `pretty_generate` method (which formats the output more
49+
verbosely and nicely).
50+
51+
## Casting non native types
52+
53+
JSON documents can only support Hashes, Arrays, Strings, Integers and Floats.
54+
55+
By default if you attempt to serialize something else, `JSON.generate` will
56+
search for a `#to_json` method on that object:
57+
58+
```ruby
59+
Position = Struct.new(:latitude, :longitude) do
60+
def to_json(state = nil, *)
61+
JSON::State.from_state(state).generate({
62+
latitude: latitude,
63+
longitude: longitude,
64+
})
65+
end
66+
end
67+
68+
JSON.generate([
69+
Position.new(12323.234, 435345.233),
70+
Position.new(23434.676, 159435.324),
71+
]) # => [{"latitude":12323.234,"longitude":435345.233},{"latitude":23434.676,"longitude":159435.324}]
72+
```
73+
74+
If a `#to_json` method isn't defined on the object, `JSON.generate` will fallback to call `#to_s`:
75+
76+
```ruby
77+
JSON.generate(Object.new) # => "#<Object:0x000000011e768b98>"
78+
```
79+
80+
Both of these behavior can be disabled using the `strict: true` option:
81+
82+
```ruby
83+
JSON.generate(Object.new, strict: true) # => Object not allowed in JSON (JSON::GeneratorError)
84+
JSON.generate(Position.new(1, 2), strict: true) # => Position not allowed in JSON (JSON::GeneratorError)
85+
```
86+
87+
## JSON::Coder
88+
89+
Since `#to_json` methods are global, it can sometimes be problematic if you need a given type to be
90+
serialized in different ways in different locations.
91+
92+
Instead it is recommended to use the newer `JSON::Coder` API:
93+
94+
```ruby
95+
module MyApp
96+
API_JSON_CODER = JSON::Coder.new do |object, is_object_key|
97+
case object
98+
when Time
99+
object.iso8601(3)
100+
else
101+
object
102+
end
103+
end
104+
end
105+
106+
puts MyApp::API_JSON_CODER.dump(Time.now.utc) # => "2025-01-21T08:41:44.286Z"
107+
```
108+
109+
The provided block is called for all objects that don't have a native JSON equivalent, and
110+
must return a Ruby object that has a native JSON equivalent.
111+
112+
It is also called for objects that do have a JSON equivalent, but are used as Hash keys, for instance `{ 1 => 2}`,
113+
as well as for strings that aren't valid UTF-8:
114+
115+
```ruby
116+
coder = JSON::Coder.new do |object, is_object_key|
117+
case object
118+
when String
119+
if !object.valid_encoding? || object.encoding != Encoding::UTF_8
120+
Base64.encode64(object)
121+
else
122+
object
123+
end
124+
else
125+
object
126+
end
127+
end
128+
```
129+
130+
## Combining JSON fragments
131+
132+
To combine JSON fragments into a bigger JSON document, you can use `JSON::Fragment`:
133+
134+
```ruby
135+
posts_json = cache.fetch_multi(post_ids) do |post_id|
136+
JSON.generate(Post.find(post_id))
137+
end
138+
posts_json.map! { |post_json| JSON::Fragment.new(post_json) }
139+
JSON.generate({ posts: posts_json, count: posts_json.count })
140+
```
141+
142+
## Pretty Printing
143+
144+
`JSON.generate` always creates the shortest possible string representation of a
145+
ruby data structure in one line. This is good for data storage or network
146+
protocols, but not so good for humans to read. Fortunately there's also
147+
`JSON.pretty_generate` that creates a more readable
148+
output:
149+
150+
```ruby
151+
puts JSON.pretty_generate([1, 2, {"a"=>3.141}, false, true, nil, 4..10])
152+
[
153+
1,
154+
2,
155+
{
156+
"a": 3.141
157+
},
158+
false,
159+
true,
160+
null,
161+
{
162+
"json_class": "Range",
163+
"data": [
164+
4,
165+
10,
166+
false
167+
]
168+
}
169+
]
170+
```
171+
172+
## Security
173+
174+
When parsing or serializing untrusted input, parser and generator options should never be user controlled.
175+
176+
```ruby
177+
# Dangerous, DO NOT DO THIS.
178+
JSON.generate(params[:data], params[:options])
179+
```
180+
181+
Security vulnerability reports relying on attacker controlled parsing or generator options will be handled as regular bug fixes.
182+
183+
## Development
184+
185+
### Prerequisites
186+
187+
1. Clone the repository
188+
2. Install dependencies with `bundle install`
189+
190+
### Testing
191+
192+
The full test suite can be run with:
193+
194+
```bash
195+
bundle exec rake test
196+
```
197+
198+
### Release
199+
200+
Update the `lib/json/version.rb` file.
201+
202+
```
203+
rbenv shell 2.6.5
204+
rake build
205+
gem push pkg/json-2.3.0.gem
206+
207+
rbenv shell jruby-9.2.9.0
208+
rake build
209+
gem push pkg/json-2.3.0-java.gem
210+
```
211+
212+
## Author
213+
214+
Florian Frank <mailto:flori@ping.de>
215+
216+
## License
217+
218+
Ruby License, see https://www.ruby-lang.org/en/about/license.txt.
219+
220+
## Download
221+
222+
The latest version of this library can be downloaded at
223+
224+
* https://rubygems.org/gems/json
225+
226+
Online Documentation should be located at
227+
228+
* https://www.rubydoc.info/gems/json

0 commit comments

Comments
 (0)