Skip to content

Commit

Permalink
Add TruffleRuby support and add it in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed May 29, 2023
1 parent 806add6 commit e7691e3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion ext/cgi/escape/extconf.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 6 additions & 3 deletions lib/cgi/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/cgi/test_cgi_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def setup
remove_method :escapeHTML
alias _unescapeHTML unescapeHTML
remove_method :unescapeHTML
end
end if defined?(CGI::Escape)
end

def teardown
Expand All @@ -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
Expand Down

0 comments on commit e7691e3

Please sign in to comment.