From e7691e3b0fded49433f570d8e912db50603e83ea Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 29 May 2023 13:53:49 +0200 Subject: [PATCH] Add TruffleRuby support and add it in CI --- .github/workflows/test.yml | 1 - ext/cgi/escape/extconf.rb | 6 +++++- lib/cgi/util.rb | 9 ++++++--- test/cgi/test_cgi_util.rb | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ff12376..90c5f38 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,6 @@ jobs: ruby-versions: uses: ruby/actions/.github/workflows/ruby_versions.yml@master with: - engine: cruby-jruby min_version: 2.5 test: needs: ruby-versions diff --git a/ext/cgi/escape/extconf.rb b/ext/cgi/escape/extconf.rb index 16e8ff2..73acd89 100644 --- a/ext/cgi/escape/extconf.rb +++ b/ext/cgi/escape/extconf.rb @@ -1,3 +1,7 @@ require 'mkmf' -create_makefile 'cgi/escape' +if RUBY_ENGINE == 'truffleruby' + File.write("Makefile", dummy_makefile($srcdir).join("")) +else + create_makefile 'cgi/escape' +end diff --git a/lib/cgi/util.rb b/lib/cgi/util.rb index 5a5c77a..5f33589 100644 --- a/lib/cgi/util.rb +++ b/lib/cgi/util.rb @@ -90,9 +90,12 @@ def escapeHTML(string) end end - begin - require 'cgi/escape' - rescue LoadError + # TruffleRuby runs the pure-Ruby variant faster, do not use the C extension there + unless RUBY_ENGINE == 'truffleruby' + begin + require 'cgi/escape' + rescue LoadError + end end # Unescape a string that has been HTML-escaped diff --git a/test/cgi/test_cgi_util.rb b/test/cgi/test_cgi_util.rb index a3be193..b3a46a1 100644 --- a/test/cgi/test_cgi_util.rb +++ b/test/cgi/test_cgi_util.rb @@ -262,7 +262,7 @@ def setup remove_method :escapeHTML alias _unescapeHTML unescapeHTML remove_method :unescapeHTML - end + end if defined?(CGI::Escape) end def teardown @@ -271,7 +271,7 @@ def teardown remove_method :_escapeHTML alias unescapeHTML _unescapeHTML remove_method :_unescapeHTML - end + end if defined?(CGI::Escape) end def test_cgi_escapeHTML_with_invalid_byte_sequence