From 64d84a9e25132efdcf4eccf93739739a7b456aef Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Mon, 20 May 2024 12:17:27 +0900 Subject: [PATCH] Add support for old strscan If we support old strscan, users can also use strscan installed as a default gem. --- .github/workflows/test.yml | 12 +++++++----- lib/rexml/parsers/baseparser.rb | 11 +++++++++++ rexml.gemspec | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fd26b9ab..0c2275c2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,21 +57,23 @@ jobs: - ubuntu-latest - macos-latest - windows-latest - ruby-version: - - "3.0" - - head + ruby-version: ${{ fromJson(needs.ruby-versions.outputs.versions) }} + exclude: + - {runs-on: macos-latest, ruby-version: 2.5} steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} - name: Install as gem + run: | + rake install + - name: Install test dependencies env: BUNDLE_PATH__SYSTEM: "true" BUNDLE_WITHOUT: "benchmark:development" run: | - rake install - bundle install + bundle install --prefer-local - name: Test run: | ruby -run -e mkdir -- tmp diff --git a/lib/rexml/parsers/baseparser.rb b/lib/rexml/parsers/baseparser.rb index d09237c5..da051a76 100644 --- a/lib/rexml/parsers/baseparser.rb +++ b/lib/rexml/parsers/baseparser.rb @@ -7,6 +7,17 @@ module REXML module Parsers + if StringScanner::Version < "3.0.8" + module StringScannerCaptures + refine StringScanner do + def captures + values_at(*(1...size)) + end + end + end + using StringScannerCaptures + end + # = Using the Pull Parser # This API is experimental, and subject to change. # parser = PullParser.new( "texttxet" ) diff --git a/rexml.gemspec b/rexml.gemspec index 97eac657..169e49dc 100644 --- a/rexml.gemspec +++ b/rexml.gemspec @@ -55,5 +55,5 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 2.5.0' - spec.add_runtime_dependency("strscan", ">= 3.0.9") + spec.add_runtime_dependency("strscan") end