diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8d5176a --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 + diff --git a/README.md b/README.md index bc52540..1ed207b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 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 diff --git a/VERSION b/VERSION index 0ea3a94..0c62199 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.0 +0.2.1 diff --git a/json-canonicalization.gemspec b/json-canonicalization.gemspec index efbb1e2..2ee4cf4 100755 --- a/json-canonicalization.gemspec +++ b/json-canonicalization.gemspec @@ -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 diff --git a/lib/json/canonicalization.rb b/lib/json/canonicalization.rb index 3967ae9..e972eaf 100644 --- a/lib/json/canonicalization.rb +++ b/lib/json/canonicalization.rb @@ -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(',') + '}' @@ -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 + diff --git a/spec/c14n_spec.rb b/spec/c14n_spec.rb index 5c8df05..f677973 100644 --- a/spec/c14n_spec.rb +++ b/spec/c14n_spec.rb @@ -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