Skip to content

Commit 8dab4c6

Browse files
committed
Support all RFC 3490 label separators
[RFC 3490][0] says: > Whenever dots are used as label separators, the following > characters MUST be recognized as dots: U+002E (full stop), U+3002 > (ideographic full stop), U+FF0E (fullwidth full stop), U+FF62 > (halfwidth ideographic full stop) I'm not sure this is correct but json-schema-test-suite went with it for now: json-schema-org/JSON-Schema-Test-Suite#776 [0]: https://datatracker.ietf.org/doc/html/rfc3490#section-3.1
1 parent b4a29d1 commit 8dab4c6

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/json_schemer/format/hostname.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ module Hostname
1212
# https://datatracker.ietf.org/doc/html/rfc5891#section-4.2.3.2
1313
LEADING_CHARACTER_CLASS = "[#{LABEL_CHARACTER_CLASS}&&[^#{MARKS}]]"
1414
LABEL_REGEX_STRING = "#{LEADING_CHARACTER_CLASS}([#{LABEL_CHARACTER_CLASS}\-]*#{LABEL_CHARACTER_CLASS})?"
15-
HOSTNAME_REGEX = /\A(#{LABEL_REGEX_STRING}\.)*#{LABEL_REGEX_STRING}\z/i.freeze
15+
# https://datatracker.ietf.org/doc/html/rfc3490#section-3.1
16+
LABEL_SEPARATOR_CHARACTER_CLASS = '[\u{002E}\u{3002}\u{FF0E}\u{FF61}]'
17+
LABEL_SEPARATOR_REGEX = /#{LABEL_SEPARATOR_CHARACTER_CLASS}/.freeze
18+
HOSTNAME_REGEX = /\A(#{LABEL_REGEX_STRING}#{LABEL_SEPARATOR_CHARACTER_CLASS})*#{LABEL_REGEX_STRING}\z/i.freeze
1619
# bin/hostname_character_classes
1720
VIRAMA_CHARACTER_CLASS = '[\u{094D}\u{09CD}\u{0A4D}\u{0ACD}\u{0B4D}\u{0BCD}\u{0C4D}\u{0CCD}\u{0D3B}\u{0D3C}\u{0D4D}\u{0DCA}\u{0E3A}\u{0EBA}\u{0F84}\u{1039}\u{103A}\u{1714}\u{1715}\u{1734}\u{17D2}\u{1A60}\u{1B44}\u{1BAA}\u{1BAB}\u{1BF2}\u{1BF3}\u{2D7F}\u{A806}\u{A82C}\u{A8C4}\u{A953}\u{A9C0}\u{AAF6}\u{ABED}\u{10A3F}\u{11046}\u{11070}\u{1107F}\u{110B9}\u{11133}\u{11134}\u{111C0}\u{11235}\u{112EA}\u{1134D}\u{113CE}\u{113CF}\u{113D0}\u{11442}\u{114C2}\u{115BF}\u{1163F}\u{116B6}\u{1172B}\u{11839}\u{1193D}\u{1193E}\u{119E0}\u{11A34}\u{11A47}\u{11A99}\u{11C3F}\u{11D44}\u{11D45}\u{11D97}\u{11F41}\u{11F42}\u{1612F}]'
1821
JOINING_TYPE_L_CHARACTER_CLASS = '[\u{A872}\u{10ACD}\u{10AD7}\u{10D00}\u{10FCB}]'
@@ -44,7 +47,7 @@ module Hostname
4447

4548
def valid_hostname?(data)
4649
hostname_size = 0
47-
data.split('.', -1).map do |label|
50+
data.split(LABEL_SEPARATOR_REGEX, -1).map do |label|
4851
a_label = SimpleIDN.to_ascii(label)
4952
return false if a_label.size > MAX_A_LABEL_SIZE
5053
hostname_size += a_label.size + 1 # include separator

0 commit comments

Comments
 (0)