Skip to content

Commit

Permalink
Finish 0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Feb 13, 2021
2 parents 3d80604 + 8ea7056 commit 411bf06
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 6 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow runs continuous CI across different versions of ruby on all branches and pull requests to develop.

name: CI
on:
push:
branches: [ '**' ]
pull_request:
branches: [ develop ]
workflow_dispatch:

jobs:
tests:
name: Ruby ${{ matrix.ruby }}
if: "contains(github.event.commits[0].message, '[ci skip]') == false"
runs-on: ubuntu-latest
env:
CI: true
strategy:
fail-fast: false
matrix:
ruby:
- 2.4
- 2.5
- 2.6
- 2.7
- ruby-head
- jruby
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Install dependencies
run: bundle install --jobs 4 --retry 3
- name: Run tests
run: bundle exec rspec spec

10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ An implementation of the JSON Canonicalization Scheme for Ruby
Implements version 5 of [draft-rundgren-json-canonicalization-scheme-05](https://tools.ietf.org/html/draft-rundgren-json-canonicalization-scheme-05#page-5).

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

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

##License
## License

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

[YARD]: https://yardoc.org/
[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
[PDD]: https://unlicense.org/#unlicensing-contributions
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
0.2.1
2 changes: 1 addition & 1 deletion json-canonicalization.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |gem|

gem.required_ruby_version = '>= 2.4'
gem.requirements = []
gem.add_development_dependency 'rspec', '~> 3.9'
gem.add_development_dependency 'rspec', '~> 3.10'
gem.add_development_dependency 'yard' , '~> 0.9'

gem.post_install_message = nil
Expand Down
19 changes: 18 additions & 1 deletion lib/json/canonicalization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,21 @@ def to_json_c14n
end
end

def encode_key(k)
case k
when String
return k.encode(Encoding::UTF_16)
end
k
end

class Hash
# Output JSON with keys sorted lexicographically
# @return [String]
def to_json_c14n
"{" + self.
keys.
sort_by {|k| k.encode(Encoding::UTF_16)}.
sort_by {|k| encode_key(k)}.
map {|k| k.to_json_c14n + ':' + self[k].to_json_c14n}
.join(',') +
'}'
Expand All @@ -81,3 +89,12 @@ def to_json_c14n
self.to_json
end
end

class Symbol
# Output JSON with control characters escaped
# @return [String]
def to_json_c14n
self.to_json
end
end

7 changes: 7 additions & 0 deletions spec/c14n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@
end
end
end

describe "special cases for hash keys" do
it "handles hash defined with symbols" do
data = { a: [{b:"b"}] }
expect(data.to_json_c14n).to eq "{\"a\":[{\"b\":\"b\"}]}"
end
end

0 comments on commit 411bf06

Please sign in to comment.