Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HYC-1986 - Sanitize html in OAI-PMH #1126

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ foo@bar:~$ bundle exec rspec spec/controllers/hyrax/users_controller_spec.rb --s
```
* Copy the output of this to the sample_solr_documents file. Add a unique `:timestamp` value to the hash (e.g. `:timestamp => "2021-11-23T16:05:33.033Z"`) so that the `spec/requests/oai_pmh_endpoint_spec.rb` tests to continue to pass.

#### Debugging database not found
If tests fail with an error like `FATAL: database "hyrax_test" does not exist` then you will likely need to create the test database manually:

```
docker compose exec web bash
rails db:create RAILS_ENV=test
```

#### Debugging Capybara feature and javascript tests
* Save a screenshot
* Put `page.save_screenshot('screenshot.png')` on the line before the failing test (you can use a different name for the file if that's helpful)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def export_as_oai_dc_xml
array_of_values = values_as_array(values)
if field_s == 'source'
add_source_to_xml(xml, array_of_values)
elsif field_s == 'description'
array_of_values.each { |v| add_field_to_xml(xml, field_s, ActionController::Base.helpers.strip_tags(v)) }
else
array_of_values.each { |v| add_field_to_xml(xml, field_s, v) }
end
Expand Down
13 changes: 13 additions & 0 deletions spec/models/concerns/blacklight/document/dublin_core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@
end
end

context 'with abstract containing html' do
let(:work) { Article.new(id: '123456', title: ['Testing HTML'],
abstract: ['This <b>abstract</b> contains <i>html</i>']
)
}

it 'returns xml document with html tables sanitized from abstract' do
xml_doc = Nokogiri::XML(document.export_as_oai_dc_xml)
desc = xml_doc.xpath('//dc:description', 'dc' => 'http://purl.org/dc/elements/1.1/').map(&:text)
expect(desc).to eq ['This abstract contains html']
end
end

context 'with thumbnail' do
let(:work) { Article.new(id: '123456', title: ['654321']) }
before do
Expand Down
Loading