From 77fb4a2e406b15ff97a54e2425fd0898ed1b80dd 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 | 1 + lib/rexml/parsers/baseparser.rb | 11 +++++++++++ rexml.gemspec | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fd26b9ab..bc4f2608 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,6 +32,7 @@ jobs: with: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true + cache-version: 2 - name: Test run: bundle exec rake test 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