| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
use crate::{Emit, class}; |
| 44 |
use makeover_layout::{Choice, Field, FieldKind}; |
| 45 |
use std::fmt::Write as _; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 55 |
pub struct Markup<'a>(pub &'a str); |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] |
| 63 |
pub enum Value<'a> { |
| 64 |
|
| 65 |
#[default] |
| 66 |
Absent, |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
Text(&'a str), |
| 76 |
|
| 77 |
On(bool), |
| 78 |
} |
| 79 |
|
| 80 |
impl<'a> Value<'a> { |
| 81 |
|
| 82 |
const fn as_text(&self) -> &'a str { |
| 83 |
match self { |
| 84 |
Self::Text(text) => text, |
| 85 |
Self::Absent | Self::On(_) => "", |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
#[derive(Debug, Clone, Copy, Default)] |
| 92 |
pub struct Filling<'a> { |
| 93 |
|
| 94 |
pub value: Value<'a>, |
| 95 |
|
| 96 |
pub trailing: Option<Markup<'a>>, |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
pub id_prefix: Option<&'a str>, |
| 109 |
} |
| 110 |
|
| 111 |
impl<'a> Filling<'a> { |
| 112 |
|
| 113 |
#[must_use] |
| 114 |
pub const fn of(value: Value<'a>) -> Self { |
| 115 |
Self { |
| 116 |
value, |
| 117 |
trailing: None, |
| 118 |
id_prefix: None, |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
fn id_for(&self, name: &str) -> String { |
| 124 |
match self.id_prefix { |
| 125 |
Some(prefix) => format!("{}-{}", escape(prefix), escape(name)), |
| 126 |
None => escape(name), |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
#[must_use] |
| 137 |
pub fn escape(text: &str) -> String { |
| 138 |
let mut out = String::with_capacity(text.len()); |
| 139 |
for ch in text.chars() { |
| 140 |
match ch { |
| 141 |
'&' => out.push_str("&"), |
| 142 |
'<' => out.push_str("<"), |
| 143 |
'>' => out.push_str(">"), |
| 144 |
'"' => out.push_str("""), |
| 145 |
'\'' => out.push_str("'"), |
| 146 |
other => out.push(other), |
| 147 |
} |
| 148 |
} |
| 149 |
out |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
const fn input_type(kind: FieldKind) -> &'static str { |
| 156 |
match kind { |
| 157 |
FieldKind::Secret => "password", |
| 158 |
FieldKind::Number => "number", |
| 159 |
FieldKind::Checkbox => "checkbox", |
| 160 |
FieldKind::Hidden => "hidden", |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
FieldKind::Email => "email", |
| 166 |
FieldKind::Url => "url", |
| 167 |
FieldKind::Tel => "tel", |
| 168 |
|
| 169 |
FieldKind::Text | FieldKind::Select | FieldKind::Textarea => "text", |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
_ => "text", |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
fn control_attributes(field: &Field<'_>, id: &str, name: &str) -> String { |
| 190 |
let mut attrs = format!(" id=\"{id}\" name=\"{}\"", escape(name)); |
| 191 |
if field.required { |
| 192 |
attrs.push_str(" required"); |
| 193 |
} |
| 194 |
if field.invalid() { |
| 195 |
attrs.push_str(" aria-invalid=\"true\""); |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
let mut described = Vec::new(); |
| 203 |
if field.hint.is_some() { |
| 204 |
described.push(format!("{id}-hint")); |
| 205 |
} |
| 206 |
if field.error.is_some() { |
| 207 |
described.push(format!("{id}-error")); |
| 208 |
} |
| 209 |
if !described.is_empty() { |
| 210 |
let _ = write!(attrs, " aria-describedby=\"{}\"", described.join(" ")); |
| 211 |
} |
| 212 |
attrs |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
fn options_html(options: &[Choice<'_>], value: &str) -> String { |
| 223 |
let mut html = String::new(); |
| 224 |
if !value.is_empty() && !options.iter().any(|opt| opt.value == value) { |
| 225 |
let escaped = escape(value); |
| 226 |
let _ = write!( |
| 227 |
html, |
| 228 |
"<option value=\"{escaped}\" selected data-unmatched=\"true\">{escaped}</option>" |
| 229 |
); |
| 230 |
} |
| 231 |
for opt in options { |
| 232 |
let selected = if opt.value == value { " selected" } else { "" }; |
| 233 |
let _ = write!( |
| 234 |
html, |
| 235 |
"<option value=\"{}\"{selected}>{}</option>", |
| 236 |
escape(opt.value), |
| 237 |
escape(opt.label) |
| 238 |
); |
| 239 |
} |
| 240 |
html |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
fn control_html(field: &Field<'_>, filling: &Filling<'_>, opts: &Emit) -> String { |
| 245 |
let id = filling.id_for(field.name); |
| 246 |
let attrs = control_attributes(field, &id, field.name); |
| 247 |
let field_class = class("field", opts); |
| 248 |
let placeholder = field.placeholder.map_or_else(String::new, |text| { |
| 249 |
format!(" placeholder=\"{}\"", escape(text)) |
| 250 |
}); |
| 251 |
|
| 252 |
match field.kind { |
| 253 |
FieldKind::Textarea => format!( |
| 254 |
"<textarea class=\"{field_class}\"{attrs}{placeholder}>{}</textarea>", |
| 255 |
escape(filling.value.as_text()) |
| 256 |
), |
| 257 |
FieldKind::Select => { |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
let options = options_html(field.options, filling.value.as_text()); |
| 262 |
format!("<select class=\"{field_class}\"{attrs}>{options}</select>") |
| 263 |
} |
| 264 |
FieldKind::Checkbox => { |
| 265 |
let checked = if matches!(filling.value, Value::On(true)) { |
| 266 |
" checked" |
| 267 |
} else { |
| 268 |
"" |
| 269 |
}; |
| 270 |
format!( |
| 271 |
"<label class=\"{}\"><input type=\"checkbox\"{attrs}{checked}><span>{}</span></label>", |
| 272 |
class("form-checkbox-label", opts), |
| 273 |
escape(field.label) |
| 274 |
) |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
FieldKind::Secret => { |
| 283 |
format!("<input type=\"password\" class=\"{field_class}\"{attrs}{placeholder}>") |
| 284 |
} |
| 285 |
kind => format!( |
| 286 |
"<input type=\"{}\" class=\"{field_class}\"{attrs}{placeholder} value=\"{}\">", |
| 287 |
input_type(kind), |
| 288 |
escape(filling.value.as_text()) |
| 289 |
), |
| 290 |
} |
| 291 |
} |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
#[must_use] |
| 321 |
pub fn field_html(field: &Field<'_>, filling: &Filling<'_>, opts: &Emit) -> String { |
| 322 |
let id = filling.id_for(field.name); |
| 323 |
|
| 324 |
if !field.kind.visible() { |
| 325 |
|
| 326 |
|
| 327 |
return format!( |
| 328 |
"<input type=\"hidden\" name=\"{}\" value=\"{}\">", |
| 329 |
escape(field.name), |
| 330 |
escape(filling.value.as_text()) |
| 331 |
); |
| 332 |
} |
| 333 |
|
| 334 |
let mut html = format!("<div class=\"{}", class("form-group", opts)); |
| 335 |
if field.invalid() { |
| 336 |
html.push_str(" has-error"); |
| 337 |
} |
| 338 |
if field.extended { |
| 339 |
|
| 340 |
|
| 341 |
html.push_str("\" data-extended=\"true"); |
| 342 |
} |
| 343 |
html.push_str("\">"); |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
if !field.kind.labels_itself() { |
| 349 |
let _ = write!( |
| 350 |
html, |
| 351 |
"<label class=\"{}\" for=\"{id}\">{}</label>", |
| 352 |
class("form-label", opts), |
| 353 |
escape(field.label) |
| 354 |
); |
| 355 |
} |
| 356 |
|
| 357 |
html.push_str(&control_html(field, filling, opts)); |
| 358 |
|
| 359 |
if let Some(hint) = field.hint { |
| 360 |
let _ = write!( |
| 361 |
html, |
| 362 |
"<div class=\"{}\" id=\"{id}-hint\">{}</div>", |
| 363 |
class("form-hint", opts), |
| 364 |
escape(hint) |
| 365 |
); |
| 366 |
} |
| 367 |
if let Some(Markup(markup)) = filling.trailing { |
| 368 |
html.push_str(markup); |
| 369 |
} |
| 370 |
if let Some(error) = field.error { |
| 371 |
let _ = write!( |
| 372 |
html, |
| 373 |
"<div class=\"{} visible\" id=\"{id}-error\" role=\"alert\">{}</div>", |
| 374 |
class("form-error", opts), |
| 375 |
escape(error) |
| 376 |
); |
| 377 |
} |
| 378 |
|
| 379 |
html.push_str("</div>"); |
| 380 |
html |
| 381 |
} |
| 382 |
|
| 383 |
#[cfg(test)] |
| 384 |
mod tests { |
| 385 |
use super::*; |
| 386 |
|
| 387 |
fn field(kind: FieldKind) -> Field<'static> { |
| 388 |
Field::new(kind, "title", "Title") |
| 389 |
} |
| 390 |
|
| 391 |
#[test] |
| 392 |
fn a_value_cannot_break_out_of_the_attribute_it_sits_in() { |
| 393 |
|
| 394 |
let filling = Filling::of(Value::Text("x\" onfocus=alert(1) autofocus=\"")); |
| 395 |
let html = field_html(&field(FieldKind::Text), &filling, &Emit::default()); |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
assert!(!html.contains("\" onfocus"), "{html}"); |
| 400 |
assert!( |
| 401 |
html.contains("value=\"x" onfocus=alert(1) autofocus="\""), |
| 402 |
"{html}" |
| 403 |
); |
| 404 |
} |
| 405 |
|
| 406 |
#[test] |
| 407 |
fn a_label_cannot_open_a_tag() { |
| 408 |
let mut f = field(FieldKind::Text); |
| 409 |
f.label = "<script>alert(1)</script>"; |
| 410 |
let html = field_html(&f, &Filling::default(), &Emit::default()); |
| 411 |
assert!(!html.contains("<script>"), "{html}"); |
| 412 |
assert!(html.contains("<script>"), "{html}"); |
| 413 |
} |
| 414 |
|
| 415 |
#[test] |
| 416 |
fn every_escaped_sink_is_covered_by_the_one_escaper() { |
| 417 |
assert_eq!(escape("&<>\"'"), "&<>"'"); |
| 418 |
|
| 419 |
|
| 420 |
assert!(escape("\"").contains(""")); |
| 421 |
} |
| 422 |
|
| 423 |
#[test] |
| 424 |
fn markup_is_the_only_way_past_the_escaping() { |
| 425 |
let filling = Filling { |
| 426 |
trailing: Some(Markup("<div class=\"recurrence-config\"></div>")), |
| 427 |
..Filling::default() |
| 428 |
}; |
| 429 |
let html = field_html(&field(FieldKind::Text), &filling, &Emit::default()); |
| 430 |
assert!( |
| 431 |
html.contains("<div class=\"recurrence-config\"></div>"), |
| 432 |
"{html}" |
| 433 |
); |
| 434 |
} |
| 435 |
|
| 436 |
#[test] |
| 437 |
fn an_invalid_field_carries_the_attribute_its_own_stylesheet_keys_on() { |
| 438 |
let mut f = field(FieldKind::Text); |
| 439 |
f.error = Some("Required"); |
| 440 |
let opts = Emit::default(); |
| 441 |
let html = field_html(&f, &Filling::default(), &opts); |
| 442 |
assert!(html.contains("aria-invalid=\"true\""), "{html}"); |
| 443 |
|
| 444 |
assert!(crate::stylesheet(&opts).contains("[aria-invalid=\"true\"]")); |
| 445 |
|
| 446 |
|
| 447 |
assert!(html.contains("has-error"), "{html}"); |
| 448 |
} |
| 449 |
|
| 450 |
#[test] |
| 451 |
fn a_valid_field_claims_nothing_about_being_invalid() { |
| 452 |
let html = field_html( |
| 453 |
&field(FieldKind::Text), |
| 454 |
&Filling::default(), |
| 455 |
&Emit::default(), |
| 456 |
); |
| 457 |
assert!(!html.contains("aria-invalid"), "{html}"); |
| 458 |
assert!(!html.contains("has-error"), "{html}"); |
| 459 |
} |
| 460 |
|
| 461 |
#[test] |
| 462 |
fn the_hint_survives_an_error_arriving() { |
| 463 |
let mut f = field(FieldKind::Text); |
| 464 |
f.hint = Some("Keep it short"); |
| 465 |
f.error = Some("Required"); |
| 466 |
let html = field_html(&f, &Filling::default(), &Emit::default()); |
| 467 |
assert!( |
| 468 |
html.contains("aria-describedby=\"title-hint title-error\""), |
| 469 |
"{html}" |
| 470 |
); |
| 471 |
} |
| 472 |
|
| 473 |
#[test] |
| 474 |
fn a_secret_never_carries_its_value_into_the_markup() { |
| 475 |
let filling = Filling::of(Value::Text("hunter2")); |
| 476 |
let html = field_html(&field(FieldKind::Secret), &filling, &Emit::default()); |
| 477 |
assert!(!html.contains("hunter2"), "{html}"); |
| 478 |
assert!(html.contains("type=\"password\""), "{html}"); |
| 479 |
} |
| 480 |
|
| 481 |
#[test] |
| 482 |
fn a_hidden_field_is_the_input_and_nothing_else() { |
| 483 |
let filling = Filling::of(Value::Text("42")); |
| 484 |
let html = field_html(&field(FieldKind::Hidden), &filling, &Emit::default()); |
| 485 |
assert_eq!(html, "<input type=\"hidden\" name=\"title\" value=\"42\">"); |
| 486 |
} |
| 487 |
|
| 488 |
#[test] |
| 489 |
fn a_checkbox_labels_itself_and_takes_no_separate_label() { |
| 490 |
let html = field_html( |
| 491 |
&field(FieldKind::Checkbox), |
| 492 |
&Filling::of(Value::On(true)), |
| 493 |
&Emit::default(), |
| 494 |
); |
| 495 |
assert!(!html.contains("form-label"), "{html}"); |
| 496 |
assert!(html.contains("checked"), "{html}"); |
| 497 |
assert!(html.contains("<span>Title</span>"), "{html}"); |
| 498 |
} |
| 499 |
|
| 500 |
#[test] |
| 501 |
fn a_select_keeps_a_value_no_option_carries() { |
| 502 |
let options = [Choice::plain("1"), Choice::plain("3"), Choice::plain("7")]; |
| 503 |
let f = Field::select("title", "Title", &options); |
| 504 |
let html = field_html(&f, &Filling::of(Value::Text("10")), &Emit::default()); |
| 505 |
assert!(html.contains("data-unmatched=\"true\""), "{html}"); |
| 506 |
|
| 507 |
|
| 508 |
assert!(html.contains("<option value=\"10\" selected"), "{html}"); |
| 509 |
} |
| 510 |
|
| 511 |
#[test] |
| 512 |
fn a_select_with_no_options_emits_an_empty_select() { |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
let f = Field::select("title", "Title", &[]); |
| 517 |
let html = field_html(&f, &Filling::default(), &Emit::default()); |
| 518 |
assert!(html.contains("<select"), "{html}"); |
| 519 |
assert!(!html.contains("<option"), "{html}"); |
| 520 |
} |
| 521 |
|
| 522 |
#[test] |
| 523 |
fn a_placeholder_comes_off_the_description_and_is_escaped() { |
| 524 |
|
| 525 |
|
| 526 |
let f = Field { |
| 527 |
placeholder: Some("x\" onfocus=alert(1) autofocus=\""), |
| 528 |
..field(FieldKind::Text) |
| 529 |
}; |
| 530 |
let html = field_html(&f, &Filling::default(), &Emit::default()); |
| 531 |
assert!(html.contains("placeholder=\""), "{html}"); |
| 532 |
assert!(!html.contains("\" onfocus"), "{html}"); |
| 533 |
} |
| 534 |
|
| 535 |
#[test] |
| 536 |
fn a_select_marks_the_option_that_matches() { |
| 537 |
let options = [Choice::plain("1"), Choice::plain("3")]; |
| 538 |
let f = Field::select("title", "Title", &options); |
| 539 |
let html = field_html(&f, &Filling::of(Value::Text("3")), &Emit::default()); |
| 540 |
assert!( |
| 541 |
html.contains("<option value=\"3\" selected>3</option>"), |
| 542 |
"{html}" |
| 543 |
); |
| 544 |
assert!(html.contains("<option value=\"1\">1</option>"), "{html}"); |
| 545 |
assert!(!html.contains("data-unmatched"), "{html}"); |
| 546 |
} |
| 547 |
|
| 548 |
#[test] |
| 549 |
fn a_textarea_carries_its_value_as_text_and_not_as_an_attribute() { |
| 550 |
let filling = Filling::of(Value::Text("two\nlines")); |
| 551 |
let html = field_html(&field(FieldKind::Textarea), &filling, &Emit::default()); |
| 552 |
assert!(html.contains(">two\nlines</textarea>"), "{html}"); |
| 553 |
} |
| 554 |
|
| 555 |
#[test] |
| 556 |
fn the_class_prefix_reaches_the_markup_as_well_as_the_stylesheet() { |
| 557 |
let opts = Emit { |
| 558 |
class_prefix: "mk-", |
| 559 |
..Emit::default() |
| 560 |
}; |
| 561 |
let html = field_html(&field(FieldKind::Text), &Filling::default(), &opts); |
| 562 |
assert!(html.contains("class=\"mk-form-group\""), "{html}"); |
| 563 |
assert!(html.contains("class=\"mk-field\""), "{html}"); |
| 564 |
} |
| 565 |
|
| 566 |
#[test] |
| 567 |
fn an_extended_field_says_so_and_leaves_the_disclosure_to_the_form() { |
| 568 |
let mut f = field(FieldKind::Text); |
| 569 |
f.extended = true; |
| 570 |
let html = field_html(&f, &Filling::default(), &Emit::default()); |
| 571 |
assert!(html.contains("data-extended=\"true\""), "{html}"); |
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
#[test] |
| 578 |
fn the_id_prefix_scopes_the_id_and_never_the_name() { |
| 579 |
let mut f = field(FieldKind::Text); |
| 580 |
f.hint = Some("Keep it short"); |
| 581 |
f.error = Some("Required"); |
| 582 |
let filling = Filling { |
| 583 |
id_prefix: Some("form-modal-task-edit"), |
| 584 |
..Filling::default() |
| 585 |
}; |
| 586 |
let html = field_html(&f, &filling, &Emit::default()); |
| 587 |
|
| 588 |
assert!( |
| 589 |
html.contains(r#"id="form-modal-task-edit-title""#), |
| 590 |
"{html}" |
| 591 |
); |
| 592 |
assert!(html.contains(r#"name="title""#), "{html}"); |
| 593 |
assert!( |
| 594 |
!html.contains(r#"name="form-modal-task-edit-title""#), |
| 595 |
"{html}" |
| 596 |
); |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
assert!( |
| 601 |
html.contains(r#"for="form-modal-task-edit-title""#), |
| 602 |
"{html}" |
| 603 |
); |
| 604 |
assert!( |
| 605 |
html.contains( |
| 606 |
r#"aria-describedby="form-modal-task-edit-title-hint form-modal-task-edit-title-error""# |
| 607 |
), |
| 608 |
"{html}" |
| 609 |
); |
| 610 |
assert!( |
| 611 |
html.contains(r#"id="form-modal-task-edit-title-hint""#), |
| 612 |
"{html}" |
| 613 |
); |
| 614 |
} |
| 615 |
|
| 616 |
#[test] |
| 617 |
fn a_hidden_field_submits_its_bare_name_under_a_prefix() { |
| 618 |
let filling = Filling { |
| 619 |
value: Value::Text("42"), |
| 620 |
id_prefix: Some("scoped"), |
| 621 |
..Filling::default() |
| 622 |
}; |
| 623 |
let html = field_html(&field(FieldKind::Hidden), &filling, &Emit::default()); |
| 624 |
assert_eq!(html, r#"<input type="hidden" name="title" value="42">"#); |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
#[test] |
| 631 |
fn the_typed_text_kinds_keep_their_input_type() { |
| 632 |
for (kind, expected) in [ |
| 633 |
(FieldKind::Email, "email"), |
| 634 |
(FieldKind::Url, "url"), |
| 635 |
(FieldKind::Tel, "tel"), |
| 636 |
] { |
| 637 |
let html = field_html(&field(kind), &Filling::default(), &Emit::default()); |
| 638 |
assert!( |
| 639 |
html.contains(&format!(r#"type="{expected}""#)), |
| 640 |
"{kind:?} emitted {html}" |
| 641 |
); |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
#[test] |
| 646 |
fn no_prefix_leaves_the_id_as_the_name() { |
| 647 |
let html = field_html( |
| 648 |
&field(FieldKind::Text), |
| 649 |
&Filling::default(), |
| 650 |
&Emit::default(), |
| 651 |
); |
| 652 |
assert!(html.contains(r#"id="title" name="title""#), "{html}"); |
| 653 |
} |
| 654 |
} |
| 655 |
|