Skip to content

Commit

Permalink
Normalize accept attribute value as a comma separated string
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownPlatypus committed Sep 22, 2024
1 parent bf6c7b4 commit e7a9318
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
7 changes: 7 additions & 0 deletions markup_fmt/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,13 @@ impl<'s> DocGen<'s> for NativeAttribute<'s> {
docs.push(Doc::text(value.split_ascii_whitespace().join(" ")));
} else if self.name.eq_ignore_ascii_case("style") {
docs.push(Doc::text(ctx.format_style_attr(&value, value_start)));
} else if self.name.eq_ignore_ascii_case("accept")
&& state
.current_tag_name
.map(|name| name.eq_ignore_ascii_case("input"))
.unwrap_or_default()
{
docs.push(Doc::text(value.split(',').map(|s| s.trim()).join(", ")));
} else {
docs.extend(reflow_owned(&value));
}
Expand Down
31 changes: 31 additions & 0 deletions markup_fmt/tests/fmt/html/attributes/accept.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<label for="movie">Choose a movie to upload:</label>

<input type="file" id="movie" name="movie" accept="video/*" />

<label for="poster">Choose a poster:</label>

<input type="file" id="poster" name="poster" accept="image/png, image/jpeg" />

<input type="file" accept=".jpg,.jpeg,.png">
<input type="file" accept="text/html,application/zip">
<input type="file" accept="text/html ">
<input type="file" accept=" ">

<input type="file" accept=" image/gif
, image/jpeg ">

<input type="file" accept="
image/gif
,
image/jpeg
">



<input type="file" accept="image/gif image/jpeg">
<div type="file" name="poster" accept=" image/png, image/jpeg " ></div>
23 changes: 23 additions & 0 deletions markup_fmt/tests/fmt/html/attributes/accept.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: markup_fmt/tests/fmt.rs
---
<label for="movie">Choose a movie to upload:</label>

<input type="file" id="movie" name="movie" accept="video/*" />

<label for="poster">Choose a poster:</label>

<input type="file" id="poster" name="poster" accept="image/png, image/jpeg" />

<input type="file" accept=".jpg, .jpeg, .png">
<input type="file" accept="text/html, application/zip">
<input type="file" accept="text/html">
<input type="file" accept="">

<input type="file" accept="image/gif, image/jpeg">

<input type="file" accept="image/gif, image/jpeg">

<input type="file" accept="image/gif image/jpeg">
<div type="file" name="poster" accept=" image/png, image/jpeg ">
</div>

0 comments on commit e7a9318

Please sign in to comment.