Skip to content
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

Disallow slashes (/) in void elements #315

Merged
merged 3 commits into from
Nov 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
[#309](https://github.com/lambda-fairy/maud/pull/309)
- Remove Iron support
[#289](https://github.com/lambda-fairy/maud/pull/289)
- Disallow slashes (`/`) in void elements
[#315](https://github.com/lambda-fairy/maud/pull/315)

## [0.22.3] - 2021-09-27

Expand Down
14 changes: 0 additions & 14 deletions docs/content/elements-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ html! {
# ;
```

Before version 0.18,
Maud allowed the curly braces to be omitted.
This syntax was [removed][#137]
and now causes an error instead.

[#137]: https://github.com/lambda-fairy/maud/pull/137

## Void elements: `br;`

Terminate a void element using a semicolon:
Expand All @@ -47,13 +40,6 @@ html! {
The result will be rendered with HTML syntax –
`<br>` not `<br />`.

Maud also supports ending a void element with a slash:
`br /`.
This syntax is [deprecated][#96]
and should not be used in new code.

[#96]: https://github.com/lambda-fairy/maud/pull/96

## Custom elements and `data` attributes

Maud also supports elements and attributes with hyphens in them.
Expand Down
6 changes: 0 additions & 6 deletions maud/tests/basic_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ fn empty_elements() {
assert_eq!(result.into_string(), "pinkie<br>pie");
}

#[test]
fn empty_elements_slash() {
let result = html! { "pinkie" br / "pie" };
assert_eq!(result.into_string(), "pinkie<br>pie");
}

#[test]
fn simple_attributes() {
let result = html! {
Expand Down
9 changes: 9 additions & 0 deletions maud/tests/warnings/void-element-slash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use maud::html;

fn main() {
html! {
br /
// Make sure we're not stopping on the first error
input type="text" /
};
}
17 changes: 17 additions & 0 deletions maud/tests/warnings/void-element-slash.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error: void elements must use `;`, not `/`
--> $DIR/void-element-slash.rs:5:12
|
5 | br /
| ^
|
= help: change this to `;`
= help: see https://github.com/lambda-fairy/maud/pull/96 for details

error: void elements must use `;`, not `/`
--> $DIR/void-element-slash.rs:7:27
|
7 | input type="text" /
| ^
|
= help: change this to `;`
= help: see https://github.com/lambda-fairy/maud/pull/96 for details
8 changes: 8 additions & 0 deletions maud_macros/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,14 @@ impl Parser {
{
// Void element
self.advance();
if punct.as_char() == '/' {
emit_error!(
punct,
"void elements must use `;`, not `/`";
help = "change this to `;`";
help = "see https://github.com/lambda-fairy/maud/pull/96 for details";
);
}
ast::ElementBody::Void {
semi_span: SpanRange::single_span(punct.span()),
}
Expand Down