Skip to content

Commit 411bf06

Browse files
committed
Finish 0.2.1
2 parents 3d80604 + 8ea7056 commit 411bf06

File tree

6 files changed

+73
-6
lines changed

6 files changed

+73
-6
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow runs continuous CI across different versions of ruby on all branches and pull requests to develop.
2+
3+
name: CI
4+
on:
5+
push:
6+
branches: [ '**' ]
7+
pull_request:
8+
branches: [ develop ]
9+
workflow_dispatch:
10+
11+
jobs:
12+
tests:
13+
name: Ruby ${{ matrix.ruby }}
14+
if: "contains(github.event.commits[0].message, '[ci skip]') == false"
15+
runs-on: ubuntu-latest
16+
env:
17+
CI: true
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
ruby:
22+
- 2.4
23+
- 2.5
24+
- 2.6
25+
- 2.7
26+
- ruby-head
27+
- jruby
28+
steps:
29+
- name: Clone repository
30+
uses: actions/checkout@v2
31+
- name: Set up Ruby
32+
uses: ruby/setup-ruby@v1
33+
with:
34+
ruby-version: ${{ matrix.ruby }}
35+
- name: Install dependencies
36+
run: bundle install --jobs 4 --retry 3
37+
- name: Run tests
38+
run: bundle exec rspec spec
39+

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ An implementation of the JSON Canonicalization Scheme for Ruby
44
Implements version 5 of [draft-rundgren-json-canonicalization-scheme-05](https://tools.ietf.org/html/draft-rundgren-json-canonicalization-scheme-05#page-5).
55

66
[![Gem Version](https://badge.fury.io/rb/json-canonicalization.png)](http://badge.fury.io/rb/json-canonicalization)
7-
[![Build Status](https://travis-ci.org/dryruby/json-canonicalization.png?branch=master)](http://travis-ci.org/dryruby/json-canonicalization)
7+
[![Build Status](https://github.com/dryruby/json-canonicalization/workflows/CI/badge.svg?branch=develop)](https://github.com/dryruby/json-canonicalization/actions?query=workflow%3ACI)
88
[![Coverage Status](https://coveralls.io/repos/dryruby/json-canonicalization/badge.svg)](https://coveralls.io/r/dryruby/json-canonicalization)
99

1010
# Description
@@ -84,10 +84,14 @@ Full documentation available on [RubyDoc](http://rubydoc.info/gems/json-canonica
8484
list in the the `README`. Alphabetical order applies.
8585
* Do note that in order for us to merge any non-trivial changes (as a rule
8686
of thumb, additions larger than about 15 lines of code), we need an
87-
explicit [public domain dedication][PDD] on record from you.
87+
explicit [public domain dedication][PDD] on record from you,
88+
which you will be asked to agree to on the first commit to a repo within the organization.
8889

89-
##License
90+
## License
9091

9192
This is free and unencumbered public domain software. For more information,
9293
see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
9394

95+
[YARD]: https://yardoc.org/
96+
[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
97+
[PDD]: https://unlicense.org/#unlicensing-contributions

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.0
1+
0.2.1

json-canonicalization.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
1919

2020
gem.required_ruby_version = '>= 2.4'
2121
gem.requirements = []
22-
gem.add_development_dependency 'rspec', '~> 3.9'
22+
gem.add_development_dependency 'rspec', '~> 3.10'
2323
gem.add_development_dependency 'yard' , '~> 0.9'
2424

2525
gem.post_install_message = nil

lib/json/canonicalization.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,21 @@ def to_json_c14n
6161
end
6262
end
6363

64+
def encode_key(k)
65+
case k
66+
when String
67+
return k.encode(Encoding::UTF_16)
68+
end
69+
k
70+
end
71+
6472
class Hash
6573
# Output JSON with keys sorted lexicographically
6674
# @return [String]
6775
def to_json_c14n
6876
"{" + self.
6977
keys.
70-
sort_by {|k| k.encode(Encoding::UTF_16)}.
78+
sort_by {|k| encode_key(k)}.
7179
map {|k| k.to_json_c14n + ':' + self[k].to_json_c14n}
7280
.join(',') +
7381
'}'
@@ -81,3 +89,12 @@ def to_json_c14n
8189
self.to_json
8290
end
8391
end
92+
93+
class Symbol
94+
# Output JSON with control characters escaped
95+
# @return [String]
96+
def to_json_c14n
97+
self.to_json
98+
end
99+
end
100+

spec/c14n_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@
99
end
1010
end
1111
end
12+
13+
describe "special cases for hash keys" do
14+
it "handles hash defined with symbols" do
15+
data = { a: [{b:"b"}] }
16+
expect(data.to_json_c14n).to eq "{\"a\":[{\"b\":\"b\"}]}"
17+
end
18+
end

0 commit comments

Comments
 (0)