From cb76d13c328fed1dcc0e46404b5ac3176b0c9811 Mon Sep 17 00:00:00 2001 From: noraj Date: Sun, 26 Jan 2025 00:43:04 +0100 Subject: [PATCH] ruby 3.4 support --- .github/workflows/ruby.yml | 2 +- .rubocop.yml | 2 +- .tool-versions | 2 +- Gemfile | 9 ++++--- Gemfile.lock | 52 +++++++++++++++++++++++++------------- ctf_party.gemspec | 5 ++-- docs/CHANGELOG.md | 7 +++++ lib/ctf_party/base64.rb | 6 ++--- lib/ctf_party/cgi.rb | 4 +-- lib/ctf_party/network.rb | 8 +++--- 10 files changed, 61 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 08db9e8..f6a9919 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['3.3', '3.2', '3.1', '3.0'] + ruby-version: ['3.4', '3.3', '3.2', '3.1'] env: BUNDLE_WITHOUT: docs development # https://bundler.io/v1.5/groups.html steps: diff --git a/.rubocop.yml b/.rubocop.yml index b55b540..fda09b6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,7 +6,7 @@ AllCops: Exclude: - 'test/*.rb' SuggestExtensions: false - TargetRubyVersion: '3.0' + TargetRubyVersion: '3.1' # ~~~ Layout ~~~ Layout/HashAlignment: Include: diff --git a/.tool-versions b/.tool-versions index 53fc61d..a09e0ba 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -ruby 3.3.0 +ruby 3.4.1 nodejs 16.13.2 diff --git a/Gemfile b/Gemfile index 8858b66..a1c4ff7 100644 --- a/Gemfile +++ b/Gemfile @@ -9,8 +9,9 @@ group :runtime, :cli do end group :runtime, :all do + gem 'base64', '~> 0.2.0' # for base64 encoding gem 'cgi', '~> 0.4.1' # url decode / html escape - gem 'uri', '~> 0.13.1' # for argument parsing + gem 'uri', '~> 1.0', '>= 1.0.2' # for url parsing end group :development, :install do @@ -28,6 +29,8 @@ group :development, :lint do end group :development, :docs do - gem 'commonmarker', '~> 0.23' # for markdown support in YARD - gem 'yard', ['>= 0.9.27', '< 0.10'] + gem 'commonmarker', '~> 2.0' # for markdown support in YARD + # gem 'yard', ['>= 0.9.27', '< 0.10'] + # https://github.com/lsegal/yard/issues/1528 + gem 'yard', github: 'ParadoxV5/yard', ref: '9e869c940859570b07b81c5eadd6070e76f6291e', branch: 'commonmarker-1.0' end diff --git a/Gemfile.lock b/Gemfile.lock index 983098c..1dd0592 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,62 +1,78 @@ +GIT + remote: https://github.com/ParadoxV5/yard.git + revision: 9e869c940859570b07b81c5eadd6070e76f6291e + ref: 9e869c940859570b07b81c5eadd6070e76f6291e + branch: commonmarker-1.0 + specs: + yard (0.9.36) + PATH remote: . specs: ctf-party (3.0.0) + base64 (~> 0.2.0) docopt (~> 0.6) - uri (>= 0.12.1, < 0.14.0) + uri (~> 1.0, >= 1.0.2) GEM remote: https://rubygems.org/ specs: ast (2.4.2) + base64 (0.2.0) cgi (0.4.1) - commonmarker (0.23.10) + commonmarker (2.0.4) + rb_sys (~> 0.9) + commonmarker (2.0.4-x86_64-linux) docopt (0.6.1) - json (2.7.2) + json (2.9.1) language_server-protocol (3.17.0.3) - minitest (5.25.1) + minitest (5.25.4) minitest-skip (0.0.3) minitest (~> 5.0) parallel (1.26.3) - parser (3.3.5.0) + parser (3.3.7.0) ast (~> 2.4.1) racc racc (1.8.1) rainbow (3.1.1) rake (13.2.1) - regexp_parser (2.9.2) - rubocop (1.66.1) + rb_sys (0.9.108) + regexp_parser (2.10.0) + rubocop (1.71.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 2.4, < 3.0) - rubocop-ast (>= 1.32.2, < 2.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.36.2, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.32.3) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.37.0) parser (>= 3.3.1.0) ruby-progressbar (1.13.0) - unicode-display_width (2.5.0) - uri (0.13.1) - yard (0.9.37) + unicode-display_width (3.1.4) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) + uri (1.0.2) PLATFORMS ruby + x86_64-linux DEPENDENCIES + base64 (~> 0.2.0) bundler (~> 2.1) cgi (~> 0.4.1) - commonmarker (~> 0.23) + commonmarker (~> 2.0) ctf-party! docopt (~> 0.6) minitest (~> 5.25) minitest-skip (~> 0.0) rake (~> 13.2) rubocop (~> 1.66) - uri (~> 0.13.1) - yard (>= 0.9.27, < 0.10) + uri (~> 1.0, >= 1.0.2) + yard! BUNDLED WITH - 2.3.6 + 2.6.2 diff --git a/ctf_party.gemspec b/ctf_party.gemspec index 2619707..b212792 100644 --- a/ctf_party.gemspec +++ b/ctf_party.gemspec @@ -37,8 +37,9 @@ Gem::Specification.new do |s| 'rubygems_mfa_required' => 'true' } - s.required_ruby_version = ['>= 3.0.0', '< 4.0'] + s.required_ruby_version = ['>= 3.1.0', '< 4.0'] + s.add_runtime_dependency('base64', '~> 0.2.0') s.add_runtime_dependency('docopt', '~> 0.6') - s.add_runtime_dependency('uri', '>= 0.12.1', '< 0.14.0') + s.add_runtime_dependency('uri', '~> 1.0', '>= 1.0.2') end diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 86853f5..d7393f4 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [unreleased] + +- **Breaking changes** + - **Drop Ruby 3.0 support** ([EOL](https://www.ruby-lang.org/en/downloads/branches/)) +- Chore: + - Add support for Ruby 3.4 + ## [3.0.0] - **Breaking changes** diff --git a/lib/ctf_party/base64.rb b/lib/ctf_party/base64.rb index 892bb9d..81765c8 100644 --- a/lib/ctf_party/base64.rb +++ b/lib/ctf_party/base64.rb @@ -14,8 +14,7 @@ class String # 'Super lib!'.to_b64 # => "U3VwZXIgbGliIQ==" def to_b64(opts = {}) opts[:mode] ||= :strict - return Base64.strict_encode64(self) if opts[:mode] == :strict || - opts[:mode] == :rfc4648 + return Base64.strict_encode64(self) if %i[strict rfc4648].include?(opts[:mode]) return Base64.encode64(self) if opts[:mode] == :rfc2045 return Base64.urlsafe_encode64(self) if opts[:mode] == :urlsafe end @@ -40,8 +39,7 @@ def to_b64!(opts = {}) # 'UnVieQ=='.from_b64 # => "Ruby" def from_b64(opts = {}) opts[:mode] ||= :strict - return Base64.strict_decode64(self) if opts[:mode] == :strict || - opts[:mode] == :rfc4648 + return Base64.strict_decode64(self) if %i[strict rfc4648].include?(opts[:mode]) return Base64.decode64(self) if opts[:mode] == :rfc2045 return Base64.urlsafe_decode64(self) if opts[:mode] == :urlsafe end diff --git a/lib/ctf_party/cgi.rb b/lib/ctf_party/cgi.rb index ae7964d..e6f6e95 100644 --- a/lib/ctf_party/cgi.rb +++ b/lib/ctf_party/cgi.rb @@ -11,7 +11,7 @@ class String # 'http://vulnerable.site/search.aspx?txt=">'.urlencode # => "http://vulnerable.site/search.aspx?txt=%22%3E%3Cscript%3Ealert(/Rubyfu/.source)%3C/script%3E" # "'Stop!' said Fred".urlencode # => "'Stop!'%20said%20Fred" def urlencode - URI::Parser.new.escape self + URI::RFC2396_PARSER.escape self end # URL-encode the string in place as described for {String#urlencode}. @@ -41,7 +41,7 @@ def urlencode_data! # "'Stop!'%20said%20Fred".urldecode # => "'Stop!' said Fred" # '%27Stop%21%27+said+Fred'.urldecode # => "'Stop!'+said+Fred" def urldecode - URI::Parser.new.unescape self + URI::RFC2396_PARSER.unescape self end # URL-decode the string in place as described for {String#urldecode}. diff --git a/lib/ctf_party/network.rb b/lib/ctf_party/network.rb index be12b9c..274c6a8 100644 --- a/lib/ctf_party/network.rb +++ b/lib/ctf_party/network.rb @@ -35,22 +35,22 @@ def ip? ipv4? || ipv6? end - # Is the string a valid URI? + # Is the string a valid (RFC 2396) URI? # @param opts [Hash] optional parameters # @option opts [Symbol] :lax Default value: `false`. # When `lax: false`, only URI matching common protocols (ftp http https ldap ldaps mailto ws wss) are recognized, # but is still a bit lax (eg. `http://` is seen as valid). # When `lax: true`, the parser will accept more types of URI (gopher magnet matrix), but will be very lax and accept # nearly anything including `:`. - # @return [Boolean] `true` if the string is a valid URI, `false` else. + # @return [Boolean] `true` if the string is a valid (RFC 2396) URI, `false` else. # @example # 'ftp://ftp.ruby-lang.org/pub/ruby/3.2/ruby-3.2.0.tar.xz'.uri? # => true # 'a:'.uri? # => false # 'a:'.uri?(lax: true) # => true def uri?(opts = {}) opts[:lax] ||= false - strict = URI::DEFAULT_PARSER.make_regexp(%w[ftp http https ldap ldaps mailto ws wss]).match?(self) - lax = URI::DEFAULT_PARSER.make_regexp.match?(self) + strict = URI::RFC2396_PARSER.make_regexp(%w[ftp http https ldap ldaps mailto ws wss]).match?(self) + lax = URI::RFC2396_PARSER.make_regexp.match?(self) if opts[:lax] == true strict || lax else