From ead2dffef4ada9e56ead8596a1ca81d48dbf8a7a Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Tue, 3 Sep 2024 12:44:11 -0600 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=94=A8=20Add=20binstubs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/bundle | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/console | 11 ++++++ bin/rake | 27 +++++++++++++ 3 files changed, 147 insertions(+) create mode 100755 bin/bundle create mode 100755 bin/console create mode 100755 bin/rake diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 0000000..42c7fd7 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,109 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'bundle' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "rubygems" + +m = Module.new do + module_function + + def invoked_as_script? + File.expand_path($0) == File.expand_path(__FILE__) + end + + def env_var_version + ENV["BUNDLER_VERSION"] + end + + def cli_arg_version + return unless invoked_as_script? # don't want to hijack other binstubs + return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + bundler_version = nil + update_index = nil + ARGV.each_with_index do |a, i| + if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN + bundler_version = a + end + next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + bundler_version = $1 + update_index = i + end + bundler_version + end + + def gemfile + gemfile = ENV["BUNDLE_GEMFILE"] + return gemfile if gemfile && !gemfile.empty? + + File.expand_path("../Gemfile", __dir__) + end + + def lockfile + lockfile = + case File.basename(gemfile) + when "gems.rb" then gemfile.sub(/\.rb$/, ".locked") + else "#{gemfile}.lock" + end + File.expand_path(lockfile) + end + + def lockfile_version + return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) + return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) + end + + def bundler_requirement + @bundler_requirement ||= + env_var_version || + cli_arg_version || + bundler_requirement_for(lockfile_version) + end + + def bundler_requirement_for(version) + return "#{Gem::Requirement.default}.a" unless version + + bundler_gem_version = Gem::Version.new(version) + + bundler_gem_version.approximate_recommendation + end + + def load_bundler! + ENV["BUNDLE_GEMFILE"] ||= gemfile + + activate_bundler + end + + def activate_bundler + gem_error = activation_error_handling do + gem "bundler", bundler_requirement + end + return if gem_error.nil? + require_error = activation_error_handling do + require "bundler/version" + end + return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" + exit 42 + end + + def activation_error_handling + yield + nil + rescue StandardError, LoadError => e + e + end +end + +m.load_bundler! + +if m.invoked_as_script? + load Gem.bin_path("bundler", "bundle") +end diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..edf5eae --- /dev/null +++ b/bin/console @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "bundler/setup" +require "ruby-openid" + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. + +require "irb" +IRB.start(__FILE__) diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..4eb7d7b --- /dev/null +++ b/bin/rake @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rake' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rake", "rake") From 4fe72955f0dff405911e676e03a09ecab9d2d50a Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Tue, 3 Sep 2024 12:45:16 -0600 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9E=95=20byebug=20for=20debugging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index b6f811a..df13193 100644 --- a/Gemfile +++ b/Gemfile @@ -4,3 +4,4 @@ source 'https://rubygems.org' gemspec gem 'rake' +gem 'byebug' From a8b4b9555c3b9d5c68e5be67adeca12e7db7a73e Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Tue, 3 Sep 2024 12:46:02 -0600 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=90=9B=20Fix=20URINorm=20for=20Ruby?= =?UTF-8?q?=203+?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/supported.yml | 57 +++++++++++++++++++++++++++++++++ lib/openid/urinorm.rb | 11 ++++--- 2 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/supported.yml diff --git a/.github/workflows/supported.yml b/.github/workflows/supported.yml new file mode 100644 index 0000000..f3a2d58 --- /dev/null +++ b/.github/workflows/supported.yml @@ -0,0 +1,57 @@ +name: Supported Ruby Matrix + +env: + K_SOUP_COV_DO: false + +on: + push: + branches: + - 'master' + tags: + - '!*' # Do not execute on tags + pull_request: + branches: + - '*' + # Allow manually triggering the workflow. + workflow_dispatch: + +permissions: + contents: read + +# Cancels all previous workflow runs for the same branch that have not yet completed. +concurrency: + # The concurrency group contains the workflow name and the branch name. + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + +jobs: + test: + name: Specs - Ruby ${{ matrix.ruby }}${{ matrix.name_extra || '' }} + if: "!contains(github.event.commits[0].message, '[ci skip]') && !contains(github.event.commits[0].message, '[skip ci]')" + env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile + runs-on: ubuntu-latest + strategy: + matrix: + include: + - ruby: "3.3" + rubygems: latest + bundler: latest + gemfile: vanilla + - ruby: "3.2" + rubygems: latest + bundler: latest + gemfile: vanilla + #- Ruby 3.1 tests are run by coverage.yml + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Ruby & RubyGems + uses: ruby/setup-ruby@v1 + with: + ruby-version: "${{ matrix.ruby }}" + rubygems: "${{ matrix.rubygems }}" + bundler: "${{ matrix.bundler }}" + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - name: Run tests + run: bundle exec rake test diff --git a/lib/openid/urinorm.rb b/lib/openid/urinorm.rb index 0654b92..497ded7 100644 --- a/lib/openid/urinorm.rb +++ b/lib/openid/urinorm.rb @@ -3,17 +3,20 @@ module OpenID module URINorm + VALID_URI_SCHEMES = ['http','https'].freeze public def URINorm.urinorm(uri) uri = URI.parse(uri) raise URI::InvalidURIError.new('no scheme') unless uri.scheme + uri.scheme = uri.scheme.downcase - unless ['http','https'].member?(uri.scheme) - raise URI::InvalidURIError.new('Not an HTTP or HTTPS URI') - end + raise URI::InvalidURIError.new('Not an HTTP or HTTPS URI') unless VALID_URI_SCHEMES.member?(uri.scheme) + + raise URI::InvalidURIError.new('no host') if uri.host.nil? # For Ruby 2.7 + + raise URI::InvalidURIError.new('no host') if uri.host.empty? # For Ruby 3+ - raise URI::InvalidURIError.new('no host') unless uri.host uri.host = uri.host.downcase uri.path = remove_dot_segments(uri.path)