Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Return the property value in an empty value rule set #131

Merged
merged 3 commits into from Sep 16, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

### Unreleased

* Improve exception message for missing value [#131](https://github.com/premailer/css_parser/pull/131)
* `:rule_set_exceptions` option added [#132](https://github.com/premailer/css_parser/pull/132)

### Version 1.11.0
Expand Down
2 changes: 2 additions & 0 deletions lib/css_parser/rule_set.rb
Expand Up @@ -93,6 +93,8 @@ def []=(property, value)
else
declarations[property] = Value.new(value)
end
rescue ArgumentError => e
raise e.exception, "#{property} #{e.message}"
end
alias add_declaration! []=

Expand Down
6 changes: 6 additions & 0 deletions test/rule_set/declarations/test_value.rb
Expand Up @@ -102,6 +102,12 @@ class RuleSetProperyTest < Minitest::Test

assert_equal true, CssParser::RuleSet::Declarations::Value.new('value').value.frozen?
end

it 'raises an exception when the value is empty' do
assert_raises ArgumentError do
CssParser::RuleSet::Declarations::Value.new
end
end
end

describe '#to_s' do
Expand Down
8 changes: 8 additions & 0 deletions test/rule_set/test_declarations.rb
Expand Up @@ -68,6 +68,14 @@ class RuleSetDeclarationsTest < Minitest::Test

assert_equal declarations.method(:[]=), declarations.method(:add_declaration!)
end

it 'raises an exception including the property when the value is empty' do
declarations = CssParser::RuleSet::Declarations.new

assert_raises ArgumentError, 'foo value is empty' do
declarations['foo'] = '!important'
end
end
end

describe '#[]' do
Expand Down