-
Notifications
You must be signed in to change notification settings - Fork 59
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
WIP: Fix handling of right angle bracket (>
) in attributes
#82
base: master
Are you sure you want to change the base?
WIP: Fix handling of right angle bracket (>
) in attributes
#82
Conversation
ce87755
to
8a988ed
Compare
>
) in attributes
@@ -4,7 +4,7 @@ | |||
|
|||
module HtmlBeautifier | |||
class HtmlParser < Parser | |||
ELEMENT_CONTENT = %r{ (?:<%.*?%>|[^>])* }mx | |||
ELEMENT_CONTENT = %r{ (?:<%.*?%>|data-action\s*=\s*"(?:[^"]*?->[^"]*?)"|[^>])* }mx |
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.
Ideally this should be generalized rather being tied to data-action
.
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.
Agreed. I simply couldn't figure out the regex magic to make it work without being this specific
@@ -623,6 +623,22 @@ | |||
expect(described_class.beautify(source)).to eq(expected) | |||
end | |||
|
|||
it "does not break for > within an attribute value" do |
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.
This verifies it doesn't break code which is already formatted correctly, but there should probably be some other tests.
i couldnt really come up with a more clever regex but testing in regex101 the following still matched,
its a bit dumber but just allows > within quotes Hmm actually it lead me to adjust it once more to the following %r{ (?:[^"]?[-%]>[^"]?|[^>])* }mx moved the erb tag or - check together [-%] im not sure if this is correct but, ill fork sometime next week and see for myself |
So i gave it a try, neither of my queries were perfect @andyw8 i did notice if your revert |
It was copied from #78 (comment) but I haven't yet looked into it. |
This is the fix suggested by @jon-sully in #78 (comment)
It may need further work and verification, so I'm only opening it as a draft for now to allow for discussion.
Also, it breaks one of the current tests:
HtmlBeautifier indents general self-closing tags