diff --git a/lib/phlex/sgml.rb b/lib/phlex/sgml.rb index b68166e0..becf3668 100644 --- a/lib/phlex/sgml.rb +++ b/lib/phlex/sgml.rb @@ -396,6 +396,10 @@ def __attributes__(attributes, buffer = +"") raise ArgumentError.new("Unsafe attribute name detected: #{k}.") end + if lower_name.to_sym == :id && k != :id + raise ArgumentError.new(":id attribute should only be passed as a lowercase symbol.") + end + case v when true buffer << " " << name diff --git a/test/phlex/view/lowercase_symbolic_id_guard.test.rb b/test/phlex/view/lowercase_symbolic_id_guard.test.rb new file mode 100644 index 00000000..9f6159ae --- /dev/null +++ b/test/phlex/view/lowercase_symbolic_id_guard.test.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +describe Phlex::SGML do + extend ViewHelper + + with "non lowercase id" do + view do + def view_template + div(iD: "a") + end + end + + it "raises" do + expect { output }.to raise_exception(Phlex::ArgumentError) + end + end + + with "non symbolic id" do + view do + def view_template + div("id" => "a") + end + end + + it "raises" do + expect { output }.to raise_exception(Phlex::ArgumentError) + end + end +end