Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

yaml-safe_load_stream3

Package Overview
Dependencies
Maintainers
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yaml-safe_load_stream3

  • 0.1.2
  • Rubygems
  • Socket score

Version published
Maintainers
3
Created
Source

YAMLSafeLoadStream provided by yaml-safe_load_stream3

Gem Version Yard Docs

Before you begin...

The yaml-safe_load_stream3 project is a fork of tsutsu/yaml-safe_load_stream2. We made ::YAML.parse_stream accept parametrized args and raise Psych::DisallowedClass as per ruby 3.1 new way of passing args. The library was renamed in order to publish it to Rubygems without conflicting with yaml-safe_load_stream and yaml-safe_load_stream2.

The yaml-safe_load_stream3 project is a fork of kontena/k8s-client.

Unfortunately the company Kontena.io went bankcrupt at the end of the year 2019. They had created many wonderful Ruby projects which we are grateful.

The yaml-safe_load_stream3 library is a community effort to keep yaml-safe_load_stream maintained without any dependencies to the former Kontena.io organization. The library was renamed in order to publish it to Rubygems without conflicting with yaml-safe_load_stream.

Abstract

The Ruby standard library YAML/Psych module defines YAML.safe_load for safely loading YAML documents

There's also YAML.load_stream for loading multi-document streams.

The problem is, there's no YAML.safe_load_stream that would safely load a stream with multiple documents.

This gem adds a very bare bones implementation of that missing feature.

Usage

There is just one method: safe_load_stream(yaml_content, optional_filename_to_be_used_in_exception_messages)

When used with a block, it will yield each document separately:

YAMLSafeLoadStream.safe_load_stream("---\nhello: world\n\n---\nhello: universe\n") do |document|
  puts document.inspect
end

# outputs:
# { 'hello' => 'world' }
# { 'hello' => 'universe' }

When used without a block, it will return an Array containing documents in the stream:

docs = YAMLSafeLoadStream.safe_load_stream("---\nhello: world\n\n---\nhello: universe\n")
puts docs.inspect

# outputs:
# [{ 'hello' => 'world' }, { 'hello' => 'universe' }]

Directly

require 'yaml/safe_load_stream'

YAMLSafeLoadStream.safe_load_stream("---\nhello: world\n\n---\nhello: universe\n")

As a refinement

require 'yaml/safe_load_stream'
using YAMLSafeLoadStream

YAML.safe_load_stream("---\nhello: world\n\n---\nhello: universe\n")

Requiring the core-ext

require 'yaml/safe_load_stream/core-ext'
YAML.safe_load_stream("---\nhello: world\n\n---\nhello: universe\n")

Installation

Add this line to your application's Gemfile:

gem 'yaml-safe_load_stream3'

And then execute:

$ bundle

Or install it yourself as:

$ gem install yaml-safe_load_stream3

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/inspec/yaml-safe_load_stream3

FAQs

Package last updated on 11 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc