Skip to content

Commit 349169c

Browse files
skyamgarpclaude
andcommitted
(MODULES-11802) Downcase charset/collate before normalising
Charset and collation names are case-insensitive in MySQL/MariaDB and the server always reports them lowercased. Downcase in normalise_utf8 so a user who supplies an uppercase value (e.g. `UTF8`) also compares in sync with the lowercase server value, rather than drifting on every run. Adds unit coverage for uppercase charset/collate input. Addresses review feedback on PR #1712. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5244dc2 commit 349169c

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

lib/puppet/type/mysql_database.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
# `utf8` is a deprecated alias for `utf8mb3` in both MySQL and MariaDB. Newer
1818
# servers (e.g. MariaDB 11 on RHEL 10) report the canonical `utf8mb3` name back,
1919
# while users typically request `utf8`. Treat the two spellings as equivalent so
20-
# the resource stays idempotent regardless of which the server reports.
20+
# the resource stays idempotent regardless of which the server reports. Charset
21+
# and collation names are case-insensitive and the server reports them
22+
# lowercased, so downcase first to also match user input such as `UTF8`.
2123
def self.normalise_utf8(value)
22-
value.to_s.sub(%r{^utf8mb3}, 'utf8')
24+
value.to_s.downcase.sub(%r{^utf8mb3}, 'utf8')
2325
end
2426

2527
newproperty(:charset) do

spec/unit/puppet/type/mysql_database_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,15 @@
5151
resource = Puppet::Type.type(:mysql_database).new(name: 'test', collate: 'utf8_general_ci')
5252
expect(resource.property(:collate).insync?('latin1_swedish_ci')).to be false
5353
end
54+
55+
it 'treats uppercase charset input as in sync with the lowercase server value' do
56+
resource = Puppet::Type.type(:mysql_database).new(name: 'test', charset: 'UTF8')
57+
expect(resource.property(:charset).insync?('utf8mb3')).to be true
58+
end
59+
60+
it 'treats uppercase collate input as in sync with the lowercase server value' do
61+
resource = Puppet::Type.type(:mysql_database).new(name: 'test', collate: 'UTF8_GENERAL_CI')
62+
expect(resource.property(:collate).insync?('utf8mb3_general_ci')).to be true
63+
end
5464
end
5565
end

0 commit comments

Comments
 (0)