Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Psych::Parser#strip_bom
strip_bom(yaml)
ext/psych/lib/psych/parser.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/ext/psych/lib/psych/parser.rb, line 81
def strip_bom yaml
if String === yaml
bom = BOM[yaml.encoding]
# delete_prefix copies even when there is no prefix, so keep the guard.
return yaml.delete_prefix(bom) if bom && yaml.start_with?(bom)
elsif yaml.respond_to?(:read) && yaml.respond_to?(:external_encoding) &&
yaml.respond_to?(:pos) && yaml.respond_to?(:seek)
bom = BOM[yaml.external_encoding]
skip_io_bom yaml, bom.b if bom
end
yaml
end
libyaml only skips a leading byte order mark when it detects the stream encoding by itself. Psych passes the encoding explicitly whenever it is known, and on that path libyaml counts the BOM as a first-line character, which shifts the column of every token on the first line and silently terminates a block mapping at the second line [Bug #13615].