Skip to content

Commit

Permalink
raise on non-symbolic and non-lowercase :id (#740)
Browse files Browse the repository at this point in the history
resolves #695
  • Loading branch information
joeldrapper authored Jul 2, 2024
2 parents de7e37c + 92d246f commit d5fb7ea
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/phlex/sgml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions test/phlex/view/lowercase_symbolic_id_guard.test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d5fb7ea

Please sign in to comment.