Skip to content
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
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ jobs:
fail-fast: false
matrix:
ruby-version:
- '3.1'
- '3.2'
- '3.3'
- '3.4'
gemfile:
- gemfiles/Gemfile.rails70
- gemfiles/Gemfile.rails71
- gemfiles/Gemfile.rails72
- gemfiles/Gemfile.rails80
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [Unreleased]
### Fixed
* Drop support for Ruby 3.0, Rails 6.1
* Support Ruby 3.4. Drop support for Ruby 3.0 and 3.1, Rails 6.1 and 7.0

### Added
## 11.4.0 / 2025-10-10
Expand Down
8 changes: 0 additions & 8 deletions gemfiles/Gemfile.rails70

This file was deleted.

43 changes: 22 additions & 21 deletions lib/ndr_import/helpers/file/delimited.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,29 @@ def determine_encodings!(safe_path, col_sep, liberal)
successful_options
end

def try_each_encoding(safe_path, col_sep, liberal, supported_encodings)
def try_each_encoding(safe_path, col_sep, liberal, supported_encodings) # rubocop:disable Metrics/MethodLength
supported_encodings.each do |delimiter_encoding, access_mode|
begin
options = {
col_sep: (col_sep || ',').force_encoding(delimiter_encoding),
liberal_parsing: liberal
}

row_num = 0
# Iterate through the file; if we reach the end, this encoding worked:
CSV.foreach(safe_path, access_mode, **options) { |_line| row_num += 1 }
return options.merge(mode: access_mode)
rescue ArgumentError => e
next if e.message =~ /invalid byte sequence/ # This encoding didn't work
raise(e)
rescue RegexpError => e
next if e.message =~ /invalid multibyte character/ # This encoding didn't work
raise(e)
rescue CSVLibrary::MalformedCSVError => e
next if e.message =~ /Invalid byte sequence/ # This encoding didn't work
raise malformed_csv_error(e, col_sep, row_num + 1, safe_path)
end
options = {
col_sep: (col_sep || ',').dup.force_encoding(delimiter_encoding),
liberal_parsing: liberal
}

row_num = 0
# Iterate through the file; if we reach the end, this encoding worked:
CSV.foreach(safe_path, access_mode, **options) { |_line| row_num += 1 }
return options.merge(mode: access_mode)
rescue ArgumentError => e
next if e.message =~ /invalid byte sequence/ # This encoding didn't work

raise(e)
rescue RegexpError => e
next if e.message =~ /invalid multibyte character/ # This encoding didn't work

raise(e)
rescue CSVLibrary::MalformedCSVError => e
next if e.message =~ /Invalid byte sequence/ # This encoding didn't work

raise malformed_csv_error(e, col_sep, row_num + 1, safe_path)
end
end

Expand Down
4 changes: 2 additions & 2 deletions ndr_import.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_dependency 'activemodel'
spec.add_dependency 'activesupport', '>= 6.1', '< 8.1'
spec.add_dependency 'activesupport', '>= 7.1', '< 8.1'
spec.add_dependency 'ndr_support', '>= 5.3.2', '< 6'

spec.add_dependency 'rubyzip', '~> 2.0'
Expand All @@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'seven-zip', '~> 1.4'
spec.add_dependency 'spreadsheet', '1.2.6'

spec.required_ruby_version = '>= 3.0'
spec.required_ruby_version = '>= 3.2'

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake', '>= 12.3.3'
Expand Down
6 changes: 3 additions & 3 deletions test/mapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,13 @@ def setup
end

test 'map should replace value' do
value = '2.0'
value = +'2.0'
TestMapper.new.replace_before_mapping(value, replace_mapping)
assert_equal '2', value
end

test 'map should not alter value' do
value = '2.1'
value = +'2.1'
TestMapper.new.replace_before_mapping(value, replace_mapping)
assert_equal '2.1', value
end
Expand Down Expand Up @@ -420,7 +420,7 @@ def setup
end

test 'map should handle array original value' do
original_value = ['C9999998', %w(Addenbrookes RGT01)]
original_value = [+'C9999998', [+'Addenbrookes', +'RGT01']]
mapped_value = TestMapper.new.mapped_line(original_value, replace_array_mapping)
assert_equal %w(RGT01 RGT01), mapped_value['hospital']
end
Expand Down
10 changes: 5 additions & 5 deletions test/non_tabular_file_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class NonTabularTestMapper

# This tests the NonTabularFileHelper class
class NonTabularFileHelperTest < ActiveSupport::TestCase
simple_divider_example = <<-STR
simple_divider_example = +<<-STR
111
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.
------
Expand Down Expand Up @@ -219,7 +219,7 @@ class NonTabularFileHelperTest < ActiveSupport::TestCase
assert results.last[0].start_with?('444')
end

no_divider_example = <<-STR
no_divider_example = +<<-STR
111
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.
STR
Expand All @@ -245,7 +245,7 @@ class NonTabularFileHelperTest < ActiveSupport::TestCase
assert results.first[0].start_with?('111')
end

simple_start_and_end_divider_example = <<-STR
simple_start_and_end_divider_example = +<<-STR
----- START -----
111
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.
Expand Down Expand Up @@ -374,7 +374,7 @@ class NonTabularFileHelperTest < ActiveSupport::TestCase
capture: !ruby/regexp /^(.*)$/i
join: "\\n"
YML
capture_example = <<-STR
capture_example = +<<-STR
This is never captured
------
1111111111
Expand Down Expand Up @@ -498,7 +498,7 @@ class NonTabularFileHelperTest < ActiveSupport::TestCase
end

test 'should conditionally preserve blank lines when joining non tabular data' do
text = <<-STR.strip_heredoc
text = +<<~STR
111
hello

Expand Down
20 changes: 10 additions & 10 deletions test/xml/control_char_escaper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,40 @@
module Xml
class ControlCharEscaperTest < ActiveSupport::TestCase
def test_should_escape_in_place
data = "test \x1c data"
data = +"test \x1c data"
escape(data)

assert_equal data, 'test 0x1c data'
end

def test_should_escape_control_character
assert_equal 'hello 0x00 world', escape("hello \x00 world")
assert_equal 'hello 0x00 world', escape(+"hello \x00 world")
end

def test_should_escape_decimal_control_character_reference
assert_equal 'hello 0x00 world', escape('hello &#00; world')
assert_equal 'hello 0x1c world', escape('hello &#28; world')
assert_equal 'hello 0x00 world', escape(+'hello &#00; world')
assert_equal 'hello 0x1c world', escape(+'hello &#28; world')
end

def test_should_escape_hexadecimal_control_character_reference
assert_equal 'hello 0x00 world', escape('hello &#x00; world')
assert_equal 'hello 0x1c world', escape('hello &#x1C; world')
assert_equal 'hello 0x00 world', escape(+'hello &#x00; world')
assert_equal 'hello 0x1c world', escape(+'hello &#x1C; world')
end

def test_should_not_escape_non_control_character_decimal_reference
assert_equal 'hell&#111; world', escape('hell&#111; world')
assert_equal 'hell&#111; world', escape(+'hell&#111; world')
end

def test_should_gracefully_handle_nonsense_decimal_input
assert_equal '&#0123456789;', escape('&#0123456789;')
assert_equal '&#0123456789;', escape(+'&#0123456789;')
end

def test_should_not_escape_non_control_character_hexadecimal_reference
assert_equal 'hell&#x6F; world', escape('hell&#x6F; world')
assert_equal 'hell&#x6F; world', escape(+'hell&#x6F; world')
end

def test_should_gracefully_handle_nonsense_hexadecimal_input
assert_equal '&#xABCDEF0123456789;', escape('&#xABCDEF0123456789;')
assert_equal '&#xABCDEF0123456789;', escape(+'&#xABCDEF0123456789;')
end

private
Expand Down