Skip to content

Commit

Permalink
feature #47715 [Form] Removing self-closing slash from <input> (Tho…
Browse files Browse the repository at this point in the history
…masLandauer)

This PR was squashed before being merged into the 6.4 branch.

Discussion
----------

[Form] Removing self-closing slash from `<input>`

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | kinda
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        | n/a

Switching form template from XHTML to HTML5 syntax.

https://validator.w3.org/nu/ says:

> Warning: Self-closing tag syntax in text/html documents is [widely discouraged](https://google.github.io/styleguide/htmlcssguide.html#Document_Type); it’s unnecessary and [interacts badly with other HTML features](https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=10809) (e.g., unquoted attribute values). If you’re using a tool that injects self-closing tag syntax into all void elements, [without any option to prevent it from doing so](prettier/prettier#5246), then consider switching to a different tool.

I haven't searched for other occurrences; waiting for some feedback first.

Commits
-------

ce4e4b6 [Form] Removing self-closing slash from `<input>`
  • Loading branch information
fabpot committed Aug 1, 2023
2 parents f40687e + ce4e4b6 commit 5fcaa74
Show file tree
Hide file tree
Showing 21 changed files with 47 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{# Attribute "required" is not supported #}
{%- set required = false -%}
{%- endif -%}
<input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
<input type="{{ type }}" {{ block('widget_attributes') }}{% if value is not empty %} value="{{ value }}"{% endif %}>
{%- endblock form_widget_simple -%}

{%- block form_widget_compound -%}
Expand Down Expand Up @@ -91,11 +91,11 @@
{%- endblock choice_widget_options -%}

{%- block checkbox_widget -%}
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %}>
{%- endblock checkbox_widget -%}

{%- block radio_widget -%}
<input type="radio" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
<input type="radio" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %}>
{%- endblock radio_widget -%}

{%- block datetime_widget -%}
Expand Down Expand Up @@ -402,7 +402,7 @@
{%- endif -%}
<form{% if name != '' %} name="{{ name }}"{% endif %} method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{{ block('attributes') }}{% if multipart %} enctype="multipart/form-data"{% endif %}>
{%- if form_method != method -%}
<input type="hidden" name="_method" value="{{ method }}" />
<input type="hidden" name="_method" value="{{ method }}">
{%- endif -%}
{%- endblock form_start -%}

Expand Down Expand Up @@ -440,7 +440,7 @@
{%- endif -%}

{%- if form_method != method -%}
<input type="hidden" name="_method" value="{{ method }}" />
<input type="hidden" name="_method" value="{{ method }}">
{%- endif -%}
{% endif -%}
{% endblock form_rest %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2772,7 +2772,7 @@ public function testWidgetAttributes()
$html = $this->renderWidget($form->createView());

// compare plain HTML to check the whitespace
$this->assertSame('<input type="text" id="text" name="text" disabled="disabled" required="required" readonly="readonly" maxlength="10" pattern="\d+" class="foobar form-control" data-foo="bar" value="value" />', $html);
$this->assertSame('<input type="text" id="text" name="text" disabled="disabled" required="required" readonly="readonly" maxlength="10" pattern="\d+" class="foobar form-control" data-foo="bar" value="value">', $html);
}

public function testWidgetAttributeNameRepeatedIfTrue()
Expand All @@ -2784,7 +2784,7 @@ public function testWidgetAttributeNameRepeatedIfTrue()
$html = $this->renderWidget($form->createView());

// foo="foo"
$this->assertSame('<input type="text" id="text" name="text" required="required" foo="foo" class="form-control" value="value" />', $html);
$this->assertSame('<input type="text" id="text" name="text" required="required" foo="foo" class="form-control" value="value">', $html);
}

public function testButtonAttributes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ protected function assertXpathNodeValue(\DOMElement $element, $expression, $node
protected function assertMatchesXpath($html, $expression, $count = 1)
{
$dom = new \DOMDocument('UTF-8');

$html = preg_replace('/(<input [^>]+)(?<!\/)>/', '$1/>', $html);

try {
// Wrap in <root> node so we can load HTML with multiple tags at
// the top level
Expand Down Expand Up @@ -2511,7 +2514,7 @@ public function testWidgetAttributes()
$html = $this->renderWidget($form->createView());

// compare plain HTML to check the whitespace
$this->assertSame('<input type="text" id="text" name="text" disabled="disabled" required="required" readonly="readonly" maxlength="10" pattern="\d+" class="foobar" data-foo="bar" value="value" />', $html);
$this->assertSame('<input type="text" id="text" name="text" disabled="disabled" required="required" readonly="readonly" maxlength="10" pattern="\d+" class="foobar" data-foo="bar" value="value">', $html);
}

public function testWidgetAttributeNameRepeatedIfTrue()
Expand All @@ -2523,7 +2526,7 @@ public function testWidgetAttributeNameRepeatedIfTrue()
$html = $this->renderWidget($form->createView());

// foo="foo"
$this->assertSame('<input type="text" id="text" name="text" required="required" foo="foo" value="value" />', $html);
$this->assertSame('<input type="text" id="text" name="text" required="required" foo="foo" value="value">', $html);
}

public function testWidgetAttributeHiddenIfFalse()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% block form_widget_simple %}
{%- set type = type|default('text') -%}
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme">
{%- endblock form_widget_simple %}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

{% block form_widget_simple %}
{%- set type = type|default('text') -%}
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme">
{%- endblock form_widget_simple %}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

{% block form_widget_simple %}
{%- set type = type|default('text') -%}
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme">
{%- endblock form_widget_simple %}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function testMoneyWidgetInIso()
$this->assertSame(<<<'HTML'
<div class="input-group">
<span class="input-group-addon">&euro; </span>
<input type="text" id="name" name="name" required="required" class="form-control" /> </div>
<input type="text" id="name" name="name" required="required" class="form-control"> </div>
HTML
, trim($this->renderWidget($view)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testMoneyWidgetInIso()
$this->assertSame(<<<'HTML'
<div class="input-group "><div class="input-group-prepend">
<span class="input-group-text">&euro; </span>
</div><input type="text" id="name" name="name" required="required" class="form-control" /></div>
</div><input type="text" id="name" name="name" required="required" class="form-control"></div>
HTML
, trim($this->renderWidget($view)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function testMoneyWidgetInIso()
->createView();

self::assertSame(<<<'HTML'
<div class="input-group "><span class="input-group-text">&euro; </span><input type="text" id="name" name="name" required="required" class="form-control" /></div>
<div class="input-group "><span class="input-group-text">&euro; </span><input type="text" id="name" name="name" required="required" class="form-control"></div>
HTML
, trim($this->renderWidget($view)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function testMoneyWidgetInIso()
->createView()
;

$this->assertSame('&euro; <input type="text" id="name" name="name" required="required" />', $this->renderWidget($view));
$this->assertSame('&euro; <input type="text" id="name" name="name" required="required">', $this->renderWidget($view));
}

public function testHelpAttr()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% extends "base.html.twig" %}

{% block body %}
Hello {{ app.user.userIdentifier }}!<br /><br />
You're browsing to path "{{ app.request.pathInfo }}".<br /><br />
Hello {{ app.user.userIdentifier }}!<br><br>
You're browsing to path "{{ app.request.pathInfo }}".<br><br>
<a href="{{ logout_path('default') }}">Log out</a>.
<a href="{{ logout_url('default') }}">Log out</a>.
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{{ form_widget(form) }}

{# Note: ensure the submit name does not conflict with the form's name or it may clobber field data #}
<input type="submit" name="login" />
<input type="submit" name="login">
</form>

{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

<form action="{{ path('localized_check_path') }}" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" />
<input type="text" id="username" name="_username" value="{{ last_username }}">

<label for="password">Password:</label>
<input type="password" id="password" name="_password" />
<input type="password" id="password" name="_password">

<input type="hidden" name="_target_path" value="" />
<input type="hidden" name="_target_path" value="">

<input type="submit" name="login" />
<input type="submit" name="login">
</form>

{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "base.html.twig" %}

{% block body %}
Hello {{ user.userIdentifier }}!<br /><br />
Hello {{ user.userIdentifier }}!<br><br>
You're browsing to path "{{ app.request.pathInfo }}".

<a href="{{ logout_path('default') }}">Log out</a>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

<form action="{{ path('form_login_check') }}" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" />
<input type="text" id="username" name="_username" value="{{ last_username }}">

<label for="password">Password:</label>
<input type="password" id="password" name="_password" />
<input type="password" id="password" name="_password">

<input type="hidden" name="_target_path" value="" />
<input type="hidden" name="_target_path" value="">

<input type="submit" name="login" />
<input type="submit" name="login">
</form>

{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="{{ _charset }}" />
<meta charset="{{ _charset }}">
<title>{% block title %}Welcome!{% endblock %}</title>
{% block stylesheets %}{% endblock %}
</head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@
<h3 class="tab-title">Notification</h3>
<div class="tab-content">
<pre class="prewrap" style="max-height: 600px">
{{- 'Subject: ' ~ notification.getSubject() }}<br/>
{{- 'Content: ' ~ notification.getContent() }}<br/>
{{- 'Importance: ' ~ notification.getImportance() }}<br/>
{{- 'Emoji: ' ~ (notification.getEmoji() is empty ? '(empty)' : notification.getEmoji()) }}<br/>
{{- 'Exception: ' ~ notification.getException() ?? '(empty)' }}<br/>
{{- 'Subject: ' ~ notification.getSubject() }}<br>
{{- 'Content: ' ~ notification.getContent() }}<br>
{{- 'Importance: ' ~ notification.getImportance() }}<br>
{{- 'Emoji: ' ~ (notification.getEmoji() is empty ? '(empty)' : notification.getEmoji()) }}<br>
{{- 'Exception: ' ~ notification.getException() ?? '(empty)' }}<br>
{{- 'ExceptionAsString: ' ~ (notification.getExceptionAsString() is empty ? '(empty)' : notification.getExceptionAsString()) }}
</pre>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="{{ _charset }}" />
<meta name="robots" content="noindex,nofollow" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta charset="{{ _charset }}">
<meta name="robots" content="noindex,nofollow">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>{% block title %}Symfony Profiler{% endblock %}</title>

{% set request_collector = profile is defined ? profile.collectors.request|default(null) : null %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="<?= $this->charset; ?>" />
<meta name="robots" content="noindex,nofollow,noarchive" />
<meta charset="<?= $this->charset; ?>">
<meta name="robots" content="noindex,nofollow,noarchive">
<title>An Error Occurred: <?= $statusText; ?></title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>❌</text></svg>">
<style><?= $this->include('assets/css/error.css'); ?></style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="<?= $this->charset; ?>" />
<meta name="robots" content="noindex,nofollow" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta charset="<?= $this->charset; ?>">
<meta name="robots" content="noindex,nofollow">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title><?= $_message; ?></title>
<link rel="icon" type="image/png" href="<?= $this->include('assets/images/favicon.png.base64'); ?>">
<style><?= $this->include('assets/css/exception.css'); ?></style>
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpKernel/Resources/welcome.html.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="robots" content="noindex,nofollow,noarchive,nosnippet,noodp,notranslate,noimageindex" />
<meta charset="UTF-8">
<meta name="robots" content="noindex,nofollow,noarchive,nosnippet,noodp,notranslate,noimageindex">
<title>Welcome to Symfony!</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>👋</text></svg>">
<style>
Expand Down

0 comments on commit 5fcaa74

Please sign in to comment.