Skip to content

Commit 6185954

Browse files
fixes #85 and #86
1 parent 352098d commit 6185954

7 files changed

Lines changed: 1044 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [1.0.5] - 2018-11-02
8+
### Fixed
9+
- Fixed a bug where fulltext html becomes nil after sanitizing. [#85](https://github.com/ebsco/edsapi-ruby/issues/85)
10+
- Fixed a bug where the url protocol is missing from fulltext custom links. [#86](https://github.com/ebsco/edsapi-ruby/issues/86)
11+
12+
713
## [1.0.4] - 2018-10-29
814
### Fixed
915
- List retrieval returns a repeating list of just the first record.
@@ -75,6 +81,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7581
### Added
7682
- Adds KW (keywords) and SH (subject heading) to solr search fields
7783

84+
[1.0.5]: https://github.com/ebsco/edsapi-ruby/compare/1.0.4...1.0.5
7885
[1.0.4]: https://github.com/ebsco/edsapi-ruby/compare/1.0.3...1.0.4
7986
[1.0.3]: https://github.com/ebsco/edsapi-ruby/compare/1.0.2...1.0.3
8087
[1.0.2]: https://github.com/ebsco/edsapi-ruby/compare/1.0.1...1.0.2

lib/ebsco/eds/record.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,14 @@ def fulltext_link(type = 'first')
421421
fulltext_links.first || {}
422422
end
423423

424+
# add protocol if needed
425+
def add_protocol(url)
426+
unless url[/\Ahttp:\/\//] || url[/\Ahttps:\/\//]
427+
url = "https://#{url}"
428+
end
429+
url
430+
end
431+
424432
# All available fulltext links.
425433
def fulltext_links
426434

@@ -514,6 +522,7 @@ def fulltext_links
514522
if ft_customlinks.count > 0
515523
ft_customlinks.each do |ft_customlink|
516524
link_url = ft_customlink['Url']
525+
link_url = add_protocol(link_url)
517526
link_label = ft_customlink['Text']
518527
link_icon = ft_customlink['Icon']
519528
links.push({url: link_url, label: link_label, icon: link_icon, type: 'customlink-fulltext', expires: false})
@@ -530,6 +539,7 @@ def non_fulltext_links
530539
if other_customlinks.count > 0
531540
other_customlinks.each do |other_customlink|
532541
link_url = other_customlink['Url']
542+
link_url = add_protocol(link_url)
533543
link_label = other_customlink['Text']
534544
link_icon = other_customlink['Icon']
535545
links.push({url: link_url, label: link_label, icon: link_icon, type: 'customlink-other', expires: false})
@@ -947,8 +957,8 @@ def html_decode_and_sanitize(data, config = nil)
947957
# need to double-unescape data with an ephtml section
948958
if html =~ /<ephtml>/
949959
html = CGI.unescapeHTML(html)
950-
html = html.gsub!(/\\"/, '"')
951-
html = html.gsub!(/\\n /, '')
960+
html = html.gsub(/\\"/, '"')
961+
html = html.gsub(/\\n /, '')
952962
end
953963

954964
Sanitize.fragment(html, sanitize_config)

lib/ebsco/eds/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module EBSCO
22
module EDS
3-
VERSION = '1.0.4'
3+
VERSION = '1.0.5'
44
end
55
end

test/cassettes/html_test/profile_2/test_sanitize_html_fulltext_no_replacements_in_gsub.yml

Lines changed: 469 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cassettes/linking_test/profile_2/test_customlinks_fulltext_missing_protocol.yml

Lines changed: 512 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/html_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,24 @@ def test_sanitize_html_fulltext
8989
end
9090
end
9191

92+
93+
def test_sanitize_html_fulltext_no_replacements_in_gsub
94+
VCR.use_cassette('html_test/profile_2/test_sanitize_html_fulltext_no_replacements_in_gsub') do
95+
session_with_sanitize = EBSCO::EDS::Session.new({guest: false,
96+
use_cache: false,
97+
profile: 'edsapi',
98+
decode_sanitize_html: true,
99+
all_subjects_search_links: true})
100+
101+
if session_with_sanitize.dbid_in_profile 'aph'
102+
record = session_with_sanitize.retrieve({dbid: 'aph', an: '87564228'})
103+
# puts 'HTML AFTER: ' + record.eds_html_fulltext.to_s
104+
assert record.eds_html_fulltext.to_s.include? '<h1 id="AN0087564228-1">Expressing Compassion in the Face of Crisis'
105+
else
106+
puts "WARNING: skipping test_sanitize_html_fulltext_no_replacements_in_gsub, bah db isn't in the profile."
107+
end
108+
session_with_sanitize.end
109+
end
110+
end
111+
92112
end

test/linking_test.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_customlinks_fulltext
2626
found_custom_fulltext = false
2727
record.fulltext_links.each do |link|
2828
found_catalog_link = true if link[:type] == 'cataloglink'
29-
found_custom_fulltext = true if link[:type] = 'customlink-fulltext'
29+
found_custom_fulltext = true if link[:type] == 'customlink-fulltext'
3030
end
3131
assert found_custom_fulltext && found_catalog_link
3232
else
@@ -36,6 +36,27 @@ def test_customlinks_fulltext
3636
end
3737
end
3838

39+
def test_customlinks_fulltext_missing_protocol
40+
VCR.use_cassette('linking_test/profile_2/test_customlinks_fulltext_missing_protocol') do
41+
session = EBSCO::EDS::Session.new({guest: false, use_cache: false, profile: 'edsapi'})
42+
if session.dbid_in_profile 'eric'
43+
record = session.retrieve({dbid: 'eric', an: 'EJ1050530'})
44+
found_customlink_fulltext = false
45+
found_protocol = false
46+
record.fulltext_links.each do |link|
47+
found_customlink_fulltext = true if link[:type] == 'customlink-fulltext'
48+
if found_customlink_fulltext
49+
found_protocol = true if link[:url] == 'https://eric.ed.gov?id=EJ1050530'
50+
end
51+
end
52+
assert found_customlink_fulltext && found_protocol
53+
else
54+
puts "WARNING: skipping test_customlinks_fulltext_missing_protocol, eric db isn't in the profile."
55+
end
56+
session.end
57+
end
58+
end
59+
3960
def test_non_fulltext_links
4061
VCR.use_cassette('linking_test/profile_3/test_non_fulltext_links') do
4162
session = EBSCO::EDS::Session.new({guest: false, use_cache: false, profile: 'edslinkapi'})
@@ -46,7 +67,7 @@ def test_non_fulltext_links
4667
found_custom_other = false
4768
record.all_links.each do |link|
4869
found_catalog_link = true if link[:type] == 'cataloglink'
49-
found_custom_other = true if link[:type] = 'customlink-other'
70+
found_custom_other = true if link[:type] == 'customlink-other'
5071
end
5172
assert found_custom_other && found_catalog_link
5273
else

0 commit comments

Comments
 (0)