Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Check syntax with unsafe_load / load #44

Merged
merged 3 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This file is used to list changes made in each version of the YamlLint gem.
- **[PR #30](https://github.com/shortdudey123/yamllint/pull/30)** - Fix Style/PercentLiteralDelimiters offense
- **[PR #37](https://github.com/shortdudey123/yamllint/pull/37)** - Update trollop to optimist to remove deprecation warnings
- **[PR #42](https://github.com/shortdudey123/yamllint/pull/42)** - Allow empty YAML files
- **[PR #44](https://github.com/shortdudey123/yamllint/pull/44)** - Check syntax with unsafe_load / load

## v0.0.9 (2016-09-16)
- **[PR #24](https://github.com/shortdudey123/yamllint/pull/24)** - Update RSpec raise_error to be more specific
Expand Down
10 changes: 9 additions & 1 deletion lib/yamllint/linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,15 @@ def check_data(yaml_data, errors_array)

# Check that the data is valid YAML
def check_syntax_valid?(yaml_data, errors_array)
YAML.safe_load(yaml_data)
# For rationale behind the use of unsafe_load, and discussion, see:
# https://github.com/shortdudey123/yamllint/issues/43
# rubocop:disable Security/YAMLLoad
if YAML.respond_to?(:unsafe_load)
YAML.unsafe_load(yaml_data)
else
YAML.load(yaml_data)
end
# rubocop:enable Security/YAMLLoad
true
rescue YAML::SyntaxError => e
errors_array << e.message
Expand Down