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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
ruby-version: 3.4
- name: Install dependencies
run: bundle install
- name: Run RuboCop against BASE..HEAD changes
Expand Down
11 changes: 2 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,19 @@ on: [push]
jobs:
test:
strategy:
fail-fast: false
matrix:
ruby-version:
- '3.0'
- '3.1'
- '3.2'
- '3.3'
- '3.4'
gemfile:
- gemfiles/Gemfile.rails70
- gemfiles/Gemfile.rails71
- gemfiles/Gemfile.rails72
- gemfiles/Gemfile.rails80
exclude:
# rails 7.2 requires ruby >= 3.1
# https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html
- ruby-version: '3.0'
gemfile: 'gemfiles/Gemfile.rails72'
# rails 8.0 requires ruby >= 3.2
# https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html
- ruby-version: '3.0'
gemfile: 'gemfiles/Gemfile.rails80'
- ruby-version: '3.1'
gemfile: 'gemfiles/Gemfile.rails80'

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Exclude unneeded files from gem package
* Add 2027 bank holidays
* Replace Public Health England naming with NHS England
* Support Ruby 3.4. Drop support for Rails 7.0, Ruby 3.0, 3.1

## 5.10.4 / 2024-11-13
### Added
Expand Down
9 changes: 0 additions & 9 deletions gemfiles/Gemfile.rails70

This file was deleted.

8 changes: 4 additions & 4 deletions lib/ndr_support/string/clean_methodable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ def clean_roman5
end

def clean_tnmcategory
sub!(/\A[tnm]/i, '')
if self =~ /\Ax\z/i
upcase
without_prefix = sub(/\A[tnm]/i, '')
if without_prefix =~ /\Ax\z/i
without_prefix.upcase
else
downcase
without_prefix.downcase
end
end

Expand Down
6 changes: 3 additions & 3 deletions ndr_support.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_dependency 'activerecord', '>= 7.0', '< 8.1'
spec.add_dependency 'activesupport', '>= 7.0', '< 8.1'
spec.add_dependency 'activerecord', '>= 7.1', '< 8.1'
spec.add_dependency 'activesupport', '>= 7.1', '< 8.1'

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake', '>= 12.3.3'

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

# Avoid std-lib minitest (which has different namespace)
spec.add_development_dependency 'minitest', '>= 5.0.0'
Expand Down
14 changes: 7 additions & 7 deletions test/utf8_encoding/control_characters_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ControlCharactersTest < Minitest::Test
end

test 'escape_control_chars! with harmless string' do
string = 'null \x00 characters suck'
string = +'null \x00 characters suck'
expected = 'null \x00 characters suck'
actual = escape_control_chars!(string)

Expand All @@ -41,7 +41,7 @@ class ControlCharactersTest < Minitest::Test
end

test 'escape_control_chars! with unprintable control characters' do
string = "null \x00 characters suck"
string = +"null \x00 characters suck"
expected = 'null 0x00 characters suck'
actual = escape_control_chars!(string)

Expand All @@ -50,24 +50,24 @@ class ControlCharactersTest < Minitest::Test
end

test 'escape_control_chars! with printable control characters' do
string = "null \x00 characters \r\n really \t suck \x07\x07\x07"
string = +"null \x00 characters \r\n really \t suck \x07\x07\x07"
expected = "null 0x00 characters \r\n really \t suck 0x070x070x07" # ring ring ring

assert_equal expected, escape_control_chars!(string)
end

test 'escape_control_chars_in_object! with array' do
array = %W( hello\tcruel \x00 world!\n \x07 )
expected = %W( hello\tcruel 0x00 world!\n 0x07 )
array = %W[hello\tcruel \x00 world!\n \x07].collect(&:dup)
expected = %W[hello\tcruel 0x00 world!\n 0x07]
actual = escape_control_chars_in_object!(array)

assert_equal expected, actual
assert_equal array.object_id, actual.object_id
end

test 'escape_control_chars_in_object! with hash' do
hash = { :a => "hello\tcruel", :b => "\x00", :c => "world!\n", :d => "\x07" }
expected = { :a => "hello\tcruel", :b => '0x00', :c => "world!\n", :d => '0x07' }
hash = { a: +"hello\tcruel", b: +"\x00", c: +"world!\n", d: +"\x07" }
expected = { a: "hello\tcruel", b: '0x00', c: "world!\n", d: '0x07' }
actual = escape_control_chars_in_object!(hash)

assert_equal expected, actual
Expand Down
10 changes: 4 additions & 6 deletions test/utf8_encoding_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: UTF-8

require 'test_helper'

class Utf8EncodingTest < Minitest::Test
Expand All @@ -14,7 +12,7 @@ class Utf8EncodingTest < Minitest::Test
end

test 'ensure_utf8! should return the same string' do
string1 = 'hello'
string1 = +'hello'
string2 = ensure_utf8!(string1)

assert string1.object_id == string2.object_id
Expand Down Expand Up @@ -68,22 +66,22 @@ class Utf8EncodingTest < Minitest::Test
end

test 'coerce_utf8! should return the same string' do
string1 = 'hello'
string1 = +'hello'
string2 = coerce_utf8!(string1)

assert string1.object_id == string2.object_id
end

test 'ensure_utf8 should convert low bytes to UTF-8 if possible' do
string1 = 'hello'.force_encoding('Windows-1252')
string1 = (+'hello').force_encoding('Windows-1252')
string2 = ensure_utf8!(string1)

assert_equal string1, string2
assert_equal 'UTF-8', string2.encoding.name
end

test 'ensure_utf8 should convert high bytes to UTF-8 if possible' do
string1 = "dash \x96 dash".force_encoding('Windows-1252')
string1 = (+"dash \x96 dash").force_encoding('Windows-1252')
assert_equal 11, string1.bytes.to_a.length
assert_equal 11, string1.chars.to_a.length

Expand Down
14 changes: 7 additions & 7 deletions test/yaml/serialization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SerializationTest < Minitest::Test
test 'should support aliases correctly' do
x = { 'c' => 5 }
hash = { 'a' => x, 'b' => x }
hash_yaml = "---\na: &1\n c: 5\nb: *1\n"
hash_yaml = +"---\na: &1\n c: 5\nb: *1\n"
assert_equal hash, load_yaml(hash_yaml), 'Deserialising known YAML with an alias'
assert_equal hash, load_yaml(dump_yaml(hash)), 'Deserialising a structure with repeated objects'
end
Expand All @@ -22,24 +22,24 @@ class SerializationTest < Minitest::Test

test 'should handle binary yaml with control chars' do
# irb> "\xC2\xA1null \x00 characters \r\n suck!".to_yaml
yaml = "--- !binary |-\n wqFudWxsIAAgY2hhcmFjdGVycyANCiBzdWNrIQ==\n"
yaml = +"--- !binary |-\n wqFudWxsIAAgY2hhcmFjdGVycyANCiBzdWNrIQ==\n"
assert_equal "¡null 0x00 characters \r\n suck!", load_yaml(yaml)

# irb> {fulltext: "\xC2\xA1null \x00 characters \r\n suck!"}.to_yaml
yamled_hash = "---\n:fulltext: !binary |-\n wqFudWxsIAAgY2hhcmFjdGVycyANCiBzdWNrIQ==\n"
yamled_hash = +"---\n:fulltext: !binary |-\n wqFudWxsIAAgY2hhcmFjdGVycyANCiBzdWNrIQ==\n"
assert_equal({ :fulltext => "¡null 0x00 characters \r\n suck!" }, load_yaml(yamled_hash))
end

# Psych doesn't always base64-encode control characters:
test 'should handle non-binary yaml with control chars' do
#irb> Psych.dump("control \x01 char \n whoops!")
chr_1_yaml = "--- ! \"control \\x01 char \\n whoops!\"\n"
chr_1_yaml = +"--- ! \"control \\x01 char \\n whoops!\"\n"
assert_equal "control 0x01 char \n whoops!", load_yaml(chr_1_yaml)
end

test 'should handle non-binary yaml with escaped things that look like control chars' do
# irb> Psych.dump(['\\x01 \\xAF \\\\xAF', "\x01 \\\x01 \x01\\\x01"])
escaped_yaml = "---\n- \"\\\\x01 \\\\xAF \\\\\\\\xAF\"\n- \"\\x01 \\\\\\x01 \\x01\\\\\\x01\"\n"
escaped_yaml = +"---\n- \"\\\\x01 \\\\xAF \\\\\\\\xAF\"\n- \"\\x01 \\\\\\x01 \\x01\\\\\\x01\"\n"
assert_equal ['\\x01 \\xAF \\\\xAF', '0x01 \\0x01 0x01\\0x01'], load_yaml(escaped_yaml)
end

Expand Down Expand Up @@ -166,7 +166,7 @@ def assert_datetimes_with_zones
end

def assert_syck_1_8_yaml_loads_correctly
yaml = "--- \nname: Dr. Doctor\000\000\000 \ndiagnosis: \"CIN 1 \\xE2\\x80\\x93 CIN 2\"\n"
yaml = +"--- \nname: Dr. Doctor\000\000\000 \ndiagnosis: \"CIN 1 \\xE2\\x80\\x93 CIN 2\"\n"
hash = load_yaml(yaml)

# The null chars should be escaped:
Expand All @@ -187,7 +187,7 @@ def assert_syck_1_8_handles_encoding(hash)

def assert_yaml_coercion_behaviour
# UTF-8, with an unmappable byte too:
yaml = "---\nfulltextreport: \"Here is \\xE2\\x80\\x93 a weird \\x9D char\"\n"
yaml = +"---\nfulltextreport: \"Here is \\xE2\\x80\\x93 a weird \\x9D char\"\n"

# By default, we'd expect the (serialised) \x9D
assert_raises(UTF8Encoding::UTF8CoercionError) { load_yaml(yaml) }
Expand Down
Loading