Skip to content

Commit 213c013

Browse files
authored
Fix hostname coercion (#33)
1 parent 8d551a1 commit 213c013

4 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## [Unreleased]
22

3+
## [0.7.3] - 2025-09-12
4+
5+
- Fix hostname coercion
6+
37
## [0.7.1] - 2025-09-07
48

59
- Add password rule

‎lib/mini_defender/rules/hostname.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def coerce(value)
1111
value.to_s
1212
.downcase
1313
.strip
14-
.gsub(/.\z/, '')
14+
.gsub(/\.\z/, '')
1515
end
1616

1717
def passes?(attribute, value, validator)

‎lib/mini_defender/version.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module MiniDefender
4-
VERSION = "0.7.2"
4+
VERSION = "0.7.3"
55
end

‎test/rules/hostname_test.rb‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'test_helper'
44

5-
class PasswordTest < Minitest::Test
5+
class HostnameTest < Minitest::Test
66
def setup
77
@rule = MiniDefender::Rules::Hostname.new
88
end
@@ -15,8 +15,13 @@ def test_pass_for_trailing_dot
1515
assert(@rule.passes?('hostname', 'www.example.com.', nil))
1616
end
1717

18-
def test_must_remove_trailing_dot
19-
assert(@rule.coerce('www.example.com'))
18+
def test_must_coerce_valid_host
19+
host = 'www.example.com'
20+
assert_equal(@rule.coerce(host), host)
21+
end
22+
23+
def test_must_coerce_remove_trailing_dot
24+
assert_equal(@rule.coerce('www.example.com.'), 'www.example.com')
2025
end
2126

2227
def test_fail_for_non_ascii

0 commit comments

Comments
 (0)