From f3ec135e6d6c5eb350b95f49d8f130defa6a7447 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Sun, 25 Oct 2020 16:17:55 -0700 Subject: [PATCH 1/4] Update PDD info in the README. --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bc52540..d580759 100644 --- a/README.md +++ b/README.md @@ -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 From dd8c50b1ba2282aaf65ae940fb619d229a88aa42 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Tue, 22 Dec 2020 11:53:02 -0800 Subject: [PATCH 2/4] Run CI on GitHub. --- .github/workflows/ci.yml | 39 +++++++++++++++++++++++++++++++++++ README.md | 2 +- json-canonicalization.gemspec | 2 +- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ci.yml 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 d580759..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 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 From 14e0300c9e309751ae894980efca2de1ae5c6647 Mon Sep 17 00:00:00 2001 From: Xavier Delamotte Date: Sat, 13 Feb 2021 12:56:52 +0000 Subject: [PATCH 3/4] Support for symbols --- lib/json/canonicalization.rb | 19 ++++++++++++++++++- spec/c14n_spec.rb | 7 +++++++ 2 files changed, 25 insertions(+), 1 deletion(-) 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 From 8ea7056eb7bab7675f269e1f9324f138b87c796a Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Sat, 13 Feb 2021 12:45:30 -0800 Subject: [PATCH 4/4] Version 0.2.1. --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 0ea3a94..0c62199 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.0 +0.2.1