-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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!: handle misleading '>' in tag attributes #565
Merged
bors
merged 1 commit into
yewstack:master
from
totorigolo:fix-selfclosing-false-positive
Aug 7, 2019
Merged
html!: handle misleading '>' in tag attributes #565
bors
merged 1 commit into
yewstack:master
from
totorigolo:fix-selfclosing-false-positive
Aug 7, 2019
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'll rebase on #564 once it gets merged, in order to move its tests into |
### Problem The html! macro didn't handle cases like this one: ```rust html! { <div onclick=|_| 2 > 1 /> // ^ this } ``` Moreover, the introduction of handling of mixed self-closing and not self-closing tags introduced a buggy error message, which is now fixed. ### Solution The parser only allows '<', '{' or nothing after a tag's closing '>'. `verify_end` is removed, and the presence of a closing tag is checked when parsing the children. Note: I also moved some tests around. ### Regression Unfortunately, this change has a regression: the error message is less good now, like here in `html-tag-fail.stderr`: ``` diff --git a/tests/macro/html-tag-fail.stderr b/tests/macro/html-tag-fail.stderr index b14fc14..d59e8f4 100644 --- a/tests/macro/html-tag-fail.stderr +++ b/tests/macro/html-tag-fail.stderr @@ -52,11 +52,13 @@ error: only one root html element allowed 12 | html! { <img /></img> }; | ^^^^^^ -error: expected valid html element - --> $DIR/html-tag-fail.rs:13:18 +error: unexpected end of input, expected token tree + --> $DIR/html-tag-fail.rs:13:5 | 13 | html! { <div>Invalid</div> }; - | ^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: only one `attr` attribute allowed --> $DIR/html-tag-fail.rs:15:27 ```
totorigolo
force-pushed
the
fix-selfclosing-false-positive
branch
from
August 7, 2019 09:53
58030e3
to
78d4376
Compare
Done! |
bors r+ |
bors bot
added a commit
that referenced
this pull request
Aug 7, 2019
565: html!: handle misleading '>' in tag attributes r=jstarry a=totorigolo ### Problem The `html!` macro didn't handle cases like this one: ```rust html! { <div onclick=|_| 2 > 1 /> // ^ this } ``` Moreover, the introduction of handling of mixed self-closing and not self-closing tags introduced a buggy error message, which is now fixed. ### Solution The parser only allows `<`, `{` or nothing after a tag's closing `>`. `verify_end` is removed, and the presence of a closing tag is checked when parsing the children. ### Regression Unfortunately, this change has a regression: the error message is less good now, like here in `html-tag-fail.stderr`: ```diff diff --git a/tests/macro/html-tag-fail.stderr b/tests/macro/html-tag-fail.stderr index b14fc14..d59e8f4 100644 --- a/tests/macro/html-tag-fail.stderr +++ b/tests/macro/html-tag-fail.stderr @@ -52,11 +52,13 @@ error: only one root html element allowed 12 | html! { <img /></img> }; | ^^^^^^ -error: expected valid html element - --> $DIR/html-tag-fail.rs:13:18 +error: unexpected end of input, expected token tree + --> $DIR/html-tag-fail.rs:13:5 | 13 | html! { <div>Invalid</div> }; - | ^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: only one `attr` attribute allowed --> $DIR/html-tag-fail.rs:15:27 ``` Co-authored-by: Thomas Lacroix <toto.rigolo@free.fr>
Build succeeded
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The
html!
macro didn't handle cases like this one:Moreover, the introduction of handling of mixed self-closing and not
self-closing tags introduced a buggy error message, which is now fixed.
Solution
The parser only allows
<
,{
or nothing after a tag's closing>
.verify_end
is removed, and the presence of a closing tag is checkedwhen parsing the children.
Regression
Unfortunately, this change has a regression: the error message is less
good now, like here in
html-tag-fail.stderr
: