Skip to content

Commit dd44073

Browse files
authored
Merge pull request #126 from rails/125-nokogiri-system-libraries
ci: add coverage for system libxml2
2 parents d1414e8 + 6a1ae1b commit dd44073

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ jobs:
3030
bundler-cache: true
3131
- run: bundle exec rake
3232

33+
cruby-nokogiri-system-libraries:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v2
37+
- uses: ruby/setup-ruby@v1
38+
with:
39+
ruby-version: "3.1"
40+
- name: Install nokogiri with system libraries
41+
run: |
42+
sudo apt install pkg-config libxml2-dev libxslt-dev
43+
bundle config set force_ruby_platform true
44+
bundle config build.nokogiri --enable-system-libraries
45+
bundle install
46+
bundle exec nokogiri -v
47+
- run: bundle exec rake
48+
3349
jruby:
3450
continue-on-error: true # nokogiri on jruby has different behavior
3551
strategy:

test/sanitizer_test.rb

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,13 @@ def test_uri_escaping_of_href_attr_in_a_tag_in_safe_list_sanitizer
505505

506506
text = safe_list_sanitize(html)
507507

508-
assert_equal %{<a href=\"examp&lt;!--%22%20unsafeattr=foo()&gt;--&gt;le.com\">test</a>}, text
508+
acceptable_results = [
509+
# nokogiri w/vendored+patched libxml2
510+
%{<a href="examp&lt;!--%22%20unsafeattr=foo()&gt;--&gt;le.com">test</a>},
511+
# nokogiri w/ system libxml2
512+
%{<a href="examp<!--%22%20unsafeattr=foo()>-->le.com">test</a>},
513+
]
514+
assert_includes(acceptable_results, text)
509515
end
510516

511517
def test_uri_escaping_of_src_attr_in_a_tag_in_safe_list_sanitizer
@@ -515,7 +521,13 @@ def test_uri_escaping_of_src_attr_in_a_tag_in_safe_list_sanitizer
515521

516522
text = safe_list_sanitize(html)
517523

518-
assert_equal %{<a src=\"examp&lt;!--%22%20unsafeattr=foo()&gt;--&gt;le.com\">test</a>}, text
524+
acceptable_results = [
525+
# nokogiri w/vendored+patched libxml2
526+
%{<a src="examp&lt;!--%22%20unsafeattr=foo()&gt;--&gt;le.com">test</a>},
527+
# nokogiri w/system libxml2
528+
%{<a src="examp<!--%22%20unsafeattr=foo()>-->le.com">test</a>},
529+
]
530+
assert_includes(acceptable_results, text)
519531
end
520532

521533
def test_uri_escaping_of_name_attr_in_a_tag_in_safe_list_sanitizer
@@ -525,7 +537,13 @@ def test_uri_escaping_of_name_attr_in_a_tag_in_safe_list_sanitizer
525537

526538
text = safe_list_sanitize(html)
527539

528-
assert_equal %{<a name=\"examp&lt;!--%22%20unsafeattr=foo()&gt;--&gt;le.com\">test</a>}, text
540+
acceptable_results = [
541+
# nokogiri w/vendored+patched libxml2
542+
%{<a name="examp&lt;!--%22%20unsafeattr=foo()&gt;--&gt;le.com">test</a>},
543+
# nokogiri w/system libxml2
544+
%{<a name="examp<!--%22%20unsafeattr=foo()>-->le.com">test</a>},
545+
]
546+
assert_includes(acceptable_results, text)
529547
end
530548

531549
def test_uri_escaping_of_name_action_in_a_tag_in_safe_list_sanitizer
@@ -535,7 +553,13 @@ def test_uri_escaping_of_name_action_in_a_tag_in_safe_list_sanitizer
535553

536554
text = safe_list_sanitize(html, attributes: ['action'])
537555

538-
assert_equal %{<a action=\"examp&lt;!--%22%20unsafeattr=foo()&gt;--&gt;le.com\">test</a>}, text
556+
acceptable_results = [
557+
# nokogiri w/vendored+patched libxml2
558+
%{<a action="examp&lt;!--%22%20unsafeattr=foo()&gt;--&gt;le.com">test</a>},
559+
# nokogiri w/system libxml2
560+
%{<a action="examp<!--%22%20unsafeattr=foo()>-->le.com">test</a>},
561+
]
562+
assert_includes(acceptable_results, text)
539563
end
540564

541565
def test_exclude_node_type_processing_instructions

0 commit comments

Comments
 (0)