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

Options validation breaking for booleans #773

Closed
jemrobinson opened this issue Oct 8, 2022 · 4 comments
Closed

Options validation breaking for booleans #773

jemrobinson opened this issue Oct 8, 2022 · 4 comments

Comments

@jemrobinson
Copy link

Problem

Setting some HTML proofer boolean flags on the command-line fails as follows:

htmlproofer html --allow-missing-href=true
htmlproofer 4.4.2 | Error:  Invalid value for 'allow_missing_href': 'true'. Expected FalseClass.
/usr/local/lib/ruby/gems/3.1.0/gems/html-proofer-4.4.2/lib/html_proofer/configuration.rb:103:in `block in validate_options': Invalid value for 'allow_missing_href': 'true'. Expected FalseClass. (TypeError)
	from /usr/local/lib/ruby/gems/3.1.0/gems/html-proofer-4.4.2/lib/html_proofer/configuration.rb:99:in `each'
	from /usr/local/lib/ruby/gems/3.1.0/gems/html-proofer-4.4.2/lib/html_proofer/configuration.rb:99:in `validate_options'
	from /usr/local/lib/ruby/gems/3.1.0/gems/html-proofer-4.4.2/lib/html_proofer/configuration.rb:52:in `generate_defaults'
	from /usr/local/lib/ruby/gems/3.1.0/gems/html-proofer-4.4.2/lib/html_proofer/runner.rb:13:in `initialize'
	from /usr/local/lib/ruby/gems/3.1.0/gems/html-proofer-4.4.2/lib/html_proofer.rb:47:in `new'
	from /usr/local/lib/ruby/gems/3.1.0/gems/html-proofer-4.4.2/lib/html_proofer.rb:47:in `check_directories'
	from /usr/local/lib/ruby/gems/3.1.0/gems/html-proofer-4.4.2/bin/htmlproofer:97:in `block (2 levels) in <top (required)>'
	from /usr/local/lib/ruby/gems/3.1.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `block in execute'
	from /usr/local/lib/ruby/gems/3.1.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `each'
	from /usr/local/lib/ruby/gems/3.1.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `execute'
	from /usr/local/lib/ruby/gems/3.1.0/gems/mercenary-0.4.0/lib/mercenary/program.rb:44:in `go'
	from /usr/local/lib/ruby/gems/3.1.0/gems/mercenary-0.4.0/lib/mercenary.rb:21:in `program'
	from /usr/local/lib/ruby/gems/3.1.0/gems/html-proofer-4.4.2/bin/htmlproofer:11:in `<top (required)>'
	from /usr/local/lib/ruby/gems/3.1.0/bin/htmlproofer:25:in `load'
	from /usr/local/lib/ruby/gems/3.1.0/bin/htmlproofer:25:in `<main>'

Cause

The update validation logic added in 12a9409 stops boolean parameters from being changed. This is because Ruby treats TrueClass and FalseClass separately, so the logic at line 103 of lib/html_proofer/configuration.rb:

raise TypeError, "Invalid value for '#{key}': '#{value}'. Expected #{default_value.class}." unless value.is_a?(default_value.class)

will always raise a TypeError if the user provides a false for a parameter which defaults to true or vice-versa.

@ribbons
Copy link

ribbons commented Oct 8, 2022

I'm also hitting this issue when calling HTMLProofer.check_directory directly.

@gjtorikian
Copy link
Owner

Shoot. Will revert and release a patch now.

@gjtorikian
Copy link
Owner

closed by #774

@jemrobinson
Copy link
Author

Thanks for the extremely quick response @gjtorikian 🎉

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants