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
HTML tag validation added for tag names #49175
HTML tag validation added for tag names #49175
Conversation
3b44bac
to
2f71a6b
Compare
2f71a6b
to
ae18a2d
Compare
ae18a2d
to
92b2c3e
Compare
Looks fine to me now, the only outstanding thing is what to allow exactly. The HTML5 spec is fairly restrictive:
https://www.w3.org/TR/2011/WD-html5-20110405/syntax.html#syntax-tag-name But I don't know if perhaps there is another later spec that allow more. I'd hate to ship something like this and to break the code of people using some less known part of the spec. |
As per the current HTML restriction, the implemented regex validates all these. |
@byroot Can we proceed with this? |
@akhilgkrishnan I see you requested a re-review, but I don't see any changes to the PR. Help me understand what you'd like me to give feedback on? |
Can I get your opinion on this? #49175 (comment) |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
980369b
to
3a0f388
Compare
7b5bb8a
to
db803a5
Compare
@flavorjones Let me know if any changes required here. cc: @byroot |
db803a5
to
25a8862
Compare
4226028
to
d3bae93
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the slight tweak to the exception message, this looks good. Thank you for taking the time to work with me on it!
Added validation for HTML tag names in the `tag` and `content_tag` helper method. The `tag` and `content_tag` method now checks that the provided tag name adheres to the HTML specification. If an invalid HTML tag name is provided, the method raises an `ArgumentError` with an appropriate error message. Examples: ```ruby content_tag("12p") # Starting with a number content_tag("") # Empty tag name tag("div/") # Contains a solidus tag("image file") # Contains a space ```
d3bae93
to
bb626ff
Compare
Thanks for your feedback and support for completing this. ❤️ |
Follow-up #49120, Also fixes the empty string
""
case of #44948Motivation / Background
As per the discussion in #49120 (comment), finally decided to have validation for invalid HTML characters in
tag
,content_tag
helper methods.Detail
Added validation for HTML tag names in the
tag
andcontent_tag
method. Thecontent_tag
method now checks that the provided tag name adheres to the HTML specification. If an invalid HTML tag name is provided, the method raises anArgumentError
with an appropriate error message.Examples:
Before:
After:
cc\ @byroot
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]