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: 1 addition & 1 deletion app/Views/welcome_message.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
<title>Welcome to CodeIgniter 4!</title>
<meta name="description" content="The small framework with powerful features">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/png" href="/favicon.ico"/>
<link rel="shortcut icon" type="image/png" href="/favicon.ico">

<!-- STYLES -->

Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Toolbar.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -408,7 +408,7 @@ public function prepare(?RequestInterface $request = null, ?ResponseInterface $r
. 'data-time="' . $time . '" '
. 'src="' . site_url() . '?debugbar"></script>'
. '<script ' . csp_script_nonce() . ' id="debugbar_dynamic_script"></script>'
. '<style type="text/css" ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
. '<style ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
. $kintScript
. PHP_EOL;

Expand Down
4 changes: 2 additions & 2 deletions system/Debug/Toolbar/Views/toolbar.tpl.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@
* @var \CodeIgniter\View\Parser $parser
*/
?>
<style type="text/css">
<style>
<?= preg_replace('#[\r\n\t ]+#', ' ', file_get_contents(__DIR__ . '/toolbar.css')) ?>
</style>

Expand DownExpand Up@@ -264,7 +264,7 @@
<?= $parser->setData($config)->render('_config.tpl') ?>
</div>
</div>
<style type="text/css">
<style>
<?php foreach ($styles as $name => $style): ?>
<?= sprintf(".%s { %s }\n", $name, $style) ?>
<?php endforeach ?>
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -2147,7 +2147,7 @@ private function printDebuggerRaw(): string
*/
protected function setErrorMessage($msg)
{
$this->debugMessage[] = $msg . '<br />';
$this->debugMessage[] = $msg . '<br>';
$this->debugMessageRaw[] = $msg;
}

Expand Down
16 changes: 9 additions & 7 deletions system/Typography/Typography.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ class Typography
public $blockElements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul';

/**
* Elements that should not have <p> and <br /> tags within them.
* Elements that should not have <p> and <br> tags within them.
*
* @var string
*/
Expand DownExpand Up@@ -63,7 +63,7 @@ class Typography
*
* This function converts text, making it typographically correct:
* - Converts double spaces into paragraphs.
* - Converts single line breaks into <br /> tags
* - Converts single line breaks into <br> tags
* - Converts single and double quotes into correctly facing curly quote entities.
* - Converts three dots into ellipsis.
* - Converts double dashes into em-dashes.
Expand DownExpand Up@@ -160,7 +160,7 @@ public function autoTypography(string $str, bool $reduceLinebreaks = false): str
$chunks[$i] .= "\n";
}

// Convert Newlines into <p> and <br /> tags
// Convert Newlines into <p> and <br> tags
$str .= $this->formatNewLines($chunks[$i]);
}

Expand DownExpand Up@@ -275,7 +275,7 @@ public function formatCharacters(string $str): string
/**
* Format Newlines
*
* Converts newline characters into either <p> tags or <br />
* Converts newline characters into either <p> tags or <br>
*/
protected function formatNewLines(string $str): string
{
Expand All@@ -286,8 +286,9 @@ protected function formatNewLines(string $str): string
// Convert two consecutive newlines to paragraphs
$str = str_replace("\n\n", "</p>\n\n<p>", $str);

// Convert single spaces to <br /> tags
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1<br />\\2\\3', $str);
// Convert single spaces to <br> tags
$br = '<br' . _solidus() . '>';
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1' . $br . '\\2\\3', $str);

// Wrap the whole enchilada in enclosing paragraphs
if ($str !== "\n") {
Expand DownExpand Up@@ -323,7 +324,8 @@ public function nl2brExceptPre(string $str): string
$newstr = '';

for ($ex = explode('pre>', $str), $ct = count($ex), $i = 0; $i < $ct; $i++) {
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i]) : $ex[$i];
$xhtml = ! (config('DocTypes')->html5 ?? false);
Comment thread
MGatner marked this conversation as resolved.
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i], $xhtml) : $ex[$i];

if ($ct - 1 !== $i) {
$newstr .= 'pre>';
Expand Down
2 changes: 1 addition & 1 deletion system/View/Filters.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,7 @@ public static function local_currency($value, string $currency, ?string $locale

/**
* Returns a string with all instances of newline character (\n)
* converted to an HTML <br/> tag.
* converted to an HTML <br> tag.
*/
public static function nl2br(string $value): string
{
Expand Down
16 changes: 8 additions & 8 deletions tests/system/Helpers/URLHelper/MiscUrlTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -498,8 +498,8 @@ public function autolinkUrls()
'This is my noreply@codeigniter.com test',
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -547,8 +547,8 @@ public function autolinkEmails()
"This is my <script>var l=new Array();l[0] = '>';l[1] = 'a';l[2] = '/';l[3] = '<';l[4] = '|109';l[5] = '|111';l[6] = '|99';l[7] = '|46';l[8] = '|114';l[9] = '|101';l[10] = '|116';l[11] = '|105';l[12] = '|110';l[13] = '|103';l[14] = '|105';l[15] = '|101';l[16] = '|100';l[17] = '|111';l[18] = '|99';l[19] = '|64';l[20] = '|121';l[21] = '|108';l[22] = '|112';l[23] = '|101';l[24] = '|114';l[25] = '|111';l[26] = '|110';l[27] = '>';l[28] = '\"';l[29] = '|109';l[30] = '|111';l[31] = '|99';l[32] = '|46';l[33] = '|114';l[34] = '|101';l[35] = '|116';l[36] = '|105';l[37] = '|110';l[38] = '|103';l[39] = '|105';l[40] = '|101';l[41] = '|100';l[42] = '|111';l[43] = '|99';l[44] = '|64';l[45] = '|121';l[46] = '|108';l[47] = '|112';l[48] = '|101';l[49] = '|114';l[50] = '|111';l[51] = '|110';l[52] = ':';l[53] = 'o';l[54] = 't';l[55] = 'l';l[56] = 'i';l[57] = 'a';l[58] = 'm';l[59] = '\"';l[60] = '=';l[61] = 'f';l[62] = 'e';l[63] = 'r';l[64] = 'h';l[65] = ' ';l[66] = 'a';l[67] = '<';for (var i = l.length-1; i >= 0; i=i-1) {if (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");else document.write(unescape(l[i]));}</script> test",
],
'test03' => [
'<br />www.google.com',
'<br />www.google.com',
'<br>www.google.com',
'<br>www.google.com',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -596,8 +596,8 @@ public function autolinkBoth()
"This is my <script>var l=new Array();l[0] = '>';l[1] = 'a';l[2] = '/';l[3] = '<';l[4] = '|109';l[5] = '|111';l[6] = '|99';l[7] = '|46';l[8] = '|114';l[9] = '|101';l[10] = '|116';l[11] = '|105';l[12] = '|110';l[13] = '|103';l[14] = '|105';l[15] = '|101';l[16] = '|100';l[17] = '|111';l[18] = '|99';l[19] = '|64';l[20] = '|121';l[21] = '|108';l[22] = '|112';l[23] = '|101';l[24] = '|114';l[25] = '|111';l[26] = '|110';l[27] = '>';l[28] = '\"';l[29] = '|109';l[30] = '|111';l[31] = '|99';l[32] = '|46';l[33] = '|114';l[34] = '|101';l[35] = '|116';l[36] = '|105';l[37] = '|110';l[38] = '|103';l[39] = '|105';l[40] = '|101';l[41] = '|100';l[42] = '|111';l[43] = '|99';l[44] = '|64';l[45] = '|121';l[46] = '|108';l[47] = '|112';l[48] = '|101';l[49] = '|114';l[50] = '|111';l[51] = '|110';l[52] = ':';l[53] = 'o';l[54] = 't';l[55] = 'l';l[56] = 'i';l[57] = 'a';l[58] = 'm';l[59] = '\"';l[60] = '=';l[61] = 'f';l[62] = 'e';l[63] = 'r';l[64] = 'h';l[65] = ' ';l[66] = 'a';l[67] = '<';for (var i = l.length-1; i >= 0; i=i-1) {if (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");else document.write(unescape(l[i]));}</script> test",
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -645,8 +645,8 @@ public function autolinkPopup()
'This is my noreply@codeigniter.com test',
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com" target="_blank">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com" target="_blank">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand Down
18 changes: 9 additions & 9 deletions tests/system/Typography/TypographyTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,11 +64,11 @@ public function testAutoTypographyLineBreaks()
"\n\n" => "\n\n<p>&nbsp;</p>",
"\n\n\n" => "\n\n<p>&nbsp;</p>",
"Line One\n" => "<p>Line One</p>\n\n",
"Line One\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r\n" => "<p>Line One</p>\n\n",
"Line One\r\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\r\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r" => "<p>Line One</p>\n\n",
"Line One\rLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\rLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p>Line Three</p>",
];

Expand All@@ -84,12 +84,12 @@ public function testAutoTypographyReduceLineBreaks()
"\n\n" => "\n\n",
"\n\n\n" => "\n\n\n\n",
"Line One\n" => "<p>Line One</p>\n\n",
"Line One\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r\n" => "<p>Line One</p>\n\n",
"Line One\r\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\r\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r" => "<p>Line One</p>\n\n",
"Line One\rLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p><br />\nLine Three</p>",
"Line One\rLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p><br>\nLine Three</p>",
];

foreach ($strs as $str => $expect) {
Expand DownExpand Up@@ -141,9 +141,9 @@ public function testAutoTypographySpecialCharacters()
public function testNewlinesToHTMLLineBreaksExceptWithinPRE()
{
$strs = [
"Line One\nLine Two" => "Line One<br />\nLine Two",
"Line One\nLine Two" => "Line One<br>\nLine Two",
"<pre>Line One\nLine Two</pre>" => "<pre>Line One\nLine Two</pre>",
"<div>Line One\nLine Two</div>" => "<div>Line One<br />\nLine Two</div>",
"<div>Line One\nLine Two</div>" => "<div>Line One<br>\nLine Two</div>",
];

foreach ($strs as $str => $expect) {
Expand Down
2 changes: 1 addition & 1 deletion tests/system/View/ParserFilterTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,7 +250,7 @@ public function testNL2BR()
$template = '{ value1|nl2br }';

$parser->setData($data);
$this->assertSame("first<br />\nsecond", $parser->renderString($template));
$this->assertSame("first<br>\nsecond", $parser->renderString($template));
}

public function testNumberFormat()
Expand Down
18 changes: 16 additions & 2 deletions user_guide_src/source/changelogs/v4.3.0.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,6 @@ The following methods of the :doc:`Time <../libraries/time>` class had bugs that
Others
------

- **Helper:** Now ``form_helper``, ``html_helper`` and common functions that render HTML elements have been changed to make void HTML elements (e.g. ``<input>``) compatible with HTML5 by default.
- **Helper:** :php:func:`script_tag()` and :php:func:`safe_mailto()` no longer output ``type="text/javascript"`` in ``<script>`` tag.
- **CLI:** The ``spark`` file has been changed due to a change in the processing of Spark commands.
- **CLI:** ``CITestStreamFilter::$buffer = ''`` no longer causes the filter to be registered to listen for streams. Now there
Expand DownExpand Up@@ -231,13 +230,28 @@ Libraries
Helpers and Functions
=====================

- Creation of void HTML elements like ``<input>`` via ``form_helper``, ``html_helper`` or common functions can be configured to exclude or not the solidus character (``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in **app/Config/DocTypes.php** to ``true``.
- Now you can autoload helpers by **app/Config/Autoload.php**.
- Added new Form helper function :php:func:`validation_errors()`, :php:func:`validation_list_errors()` and :php:func:`validation_show_error()` to display Validation Errors.
- You can set the locale to :php:func:`route_to()` if you pass a locale value as the last parameter.
- Added :php:func:`request()` and :php:func:`response()` functions.
- Added :php:func:`decamelize()` function to convert camelCase to snake_case.

HTML5 Compatibility
===================

Creation of void HTML elements like ``<input>`` can be configured to exclude or not the solidus character
(``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in
**app/Config/DocTypes.php**. If you set it to ``true``, HTML5 compatible tags without ``/`` like ``<br>``
will be output.

The following items are affected:

- Typography class: Creation of ``br`` tag
- View Parser: The ``nl2br`` filter
- Form helper
- HTML helper
- Common Functions

Error Handling
==============

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
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: 1 addition & 1 deletion app/Views/welcome_message.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
<title>Welcome to CodeIgniter 4!</title>
<meta name="description" content="The small framework with powerful features">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/png" href="/favicon.ico"/>
<link rel="shortcut icon" type="image/png" href="/favicon.ico">

<!-- STYLES -->

Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Toolbar.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -408,7 +408,7 @@ public function prepare(?RequestInterface $request = null, ?ResponseInterface $r
. 'data-time="' . $time . '" '
. 'src="' . site_url() . '?debugbar"></script>'
. '<script ' . csp_script_nonce() . ' id="debugbar_dynamic_script"></script>'
. '<style type="text/css" ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
. '<style ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
. $kintScript
. PHP_EOL;

Expand Down
4 changes: 2 additions & 2 deletions system/Debug/Toolbar/Views/toolbar.tpl.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@
* @var \CodeIgniter\View\Parser $parser
*/
?>
<style type="text/css">
<style>
<?= preg_replace('#[\r\n\t ]+#', ' ', file_get_contents(__DIR__ . '/toolbar.css')) ?>
</style>

Expand DownExpand Up@@ -264,7 +264,7 @@
<?= $parser->setData($config)->render('_config.tpl') ?>
</div>
</div>
<style type="text/css">
<style>
<?php foreach ($styles as $name => $style): ?>
<?= sprintf(".%s { %s }\n", $name, $style) ?>
<?php endforeach ?>
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -2147,7 +2147,7 @@ private function printDebuggerRaw(): string
*/
protected function setErrorMessage($msg)
{
$this->debugMessage[] = $msg . '<br />';
$this->debugMessage[] = $msg . '<br>';
$this->debugMessageRaw[] = $msg;
}

Expand Down
16 changes: 9 additions & 7 deletions system/Typography/Typography.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ class Typography
public $blockElements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul';

/**
* Elements that should not have <p> and <br /> tags within them.
* Elements that should not have <p> and <br> tags within them.
*
* @var string
*/
Expand DownExpand Up@@ -63,7 +63,7 @@ class Typography
*
* This function converts text, making it typographically correct:
* - Converts double spaces into paragraphs.
* - Converts single line breaks into <br /> tags
* - Converts single line breaks into <br> tags
* - Converts single and double quotes into correctly facing curly quote entities.
* - Converts three dots into ellipsis.
* - Converts double dashes into em-dashes.
Expand DownExpand Up@@ -160,7 +160,7 @@ public function autoTypography(string $str, bool $reduceLinebreaks = false): str
$chunks[$i] .= "\n";
}

// Convert Newlines into <p> and <br /> tags
// Convert Newlines into <p> and <br> tags
$str .= $this->formatNewLines($chunks[$i]);
}

Expand DownExpand Up@@ -275,7 +275,7 @@ public function formatCharacters(string $str): string
/**
* Format Newlines
*
* Converts newline characters into either <p> tags or <br />
* Converts newline characters into either <p> tags or <br>
*/
protected function formatNewLines(string $str): string
{
Expand All@@ -286,8 +286,9 @@ protected function formatNewLines(string $str): string
// Convert two consecutive newlines to paragraphs
$str = str_replace("\n\n", "</p>\n\n<p>", $str);

// Convert single spaces to <br /> tags
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1<br />\\2\\3', $str);
// Convert single spaces to <br> tags
$br = '<br' . _solidus() . '>';
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1' . $br . '\\2\\3', $str);

// Wrap the whole enchilada in enclosing paragraphs
if ($str !== "\n") {
Expand DownExpand Up@@ -323,7 +324,8 @@ public function nl2brExceptPre(string $str): string
$newstr = '';

for ($ex = explode('pre>', $str), $ct = count($ex), $i = 0; $i < $ct; $i++) {
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i]) : $ex[$i];
$xhtml = ! (config('DocTypes')->html5 ?? false);
Comment thread
MGatner marked this conversation as resolved.
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i], $xhtml) : $ex[$i];

if ($ct - 1 !== $i) {
$newstr .= 'pre>';
Expand Down
2 changes: 1 addition & 1 deletion system/View/Filters.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,7 @@ public static function local_currency($value, string $currency, ?string $locale

/**
* Returns a string with all instances of newline character (\n)
* converted to an HTML <br/> tag.
* converted to an HTML <br> tag.
*/
public static function nl2br(string $value): string
{
Expand Down
16 changes: 8 additions & 8 deletions tests/system/Helpers/URLHelper/MiscUrlTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -498,8 +498,8 @@ public function autolinkUrls()
'This is my noreply@codeigniter.com test',
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -547,8 +547,8 @@ public function autolinkEmails()
"This is my <script>var l=new Array();l[0] = '>';l[1] = 'a';l[2] = '/';l[3] = '<';l[4] = '|109';l[5] = '|111';l[6] = '|99';l[7] = '|46';l[8] = '|114';l[9] = '|101';l[10] = '|116';l[11] = '|105';l[12] = '|110';l[13] = '|103';l[14] = '|105';l[15] = '|101';l[16] = '|100';l[17] = '|111';l[18] = '|99';l[19] = '|64';l[20] = '|121';l[21] = '|108';l[22] = '|112';l[23] = '|101';l[24] = '|114';l[25] = '|111';l[26] = '|110';l[27] = '>';l[28] = '\"';l[29] = '|109';l[30] = '|111';l[31] = '|99';l[32] = '|46';l[33] = '|114';l[34] = '|101';l[35] = '|116';l[36] = '|105';l[37] = '|110';l[38] = '|103';l[39] = '|105';l[40] = '|101';l[41] = '|100';l[42] = '|111';l[43] = '|99';l[44] = '|64';l[45] = '|121';l[46] = '|108';l[47] = '|112';l[48] = '|101';l[49] = '|114';l[50] = '|111';l[51] = '|110';l[52] = ':';l[53] = 'o';l[54] = 't';l[55] = 'l';l[56] = 'i';l[57] = 'a';l[58] = 'm';l[59] = '\"';l[60] = '=';l[61] = 'f';l[62] = 'e';l[63] = 'r';l[64] = 'h';l[65] = ' ';l[66] = 'a';l[67] = '<';for (var i = l.length-1; i >= 0; i=i-1) {if (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");else document.write(unescape(l[i]));}</script> test",
],
'test03' => [
'<br />www.google.com',
'<br />www.google.com',
'<br>www.google.com',
'<br>www.google.com',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -596,8 +596,8 @@ public function autolinkBoth()
"This is my <script>var l=new Array();l[0] = '>';l[1] = 'a';l[2] = '/';l[3] = '<';l[4] = '|109';l[5] = '|111';l[6] = '|99';l[7] = '|46';l[8] = '|114';l[9] = '|101';l[10] = '|116';l[11] = '|105';l[12] = '|110';l[13] = '|103';l[14] = '|105';l[15] = '|101';l[16] = '|100';l[17] = '|111';l[18] = '|99';l[19] = '|64';l[20] = '|121';l[21] = '|108';l[22] = '|112';l[23] = '|101';l[24] = '|114';l[25] = '|111';l[26] = '|110';l[27] = '>';l[28] = '\"';l[29] = '|109';l[30] = '|111';l[31] = '|99';l[32] = '|46';l[33] = '|114';l[34] = '|101';l[35] = '|116';l[36] = '|105';l[37] = '|110';l[38] = '|103';l[39] = '|105';l[40] = '|101';l[41] = '|100';l[42] = '|111';l[43] = '|99';l[44] = '|64';l[45] = '|121';l[46] = '|108';l[47] = '|112';l[48] = '|101';l[49] = '|114';l[50] = '|111';l[51] = '|110';l[52] = ':';l[53] = 'o';l[54] = 't';l[55] = 'l';l[56] = 'i';l[57] = 'a';l[58] = 'm';l[59] = '\"';l[60] = '=';l[61] = 'f';l[62] = 'e';l[63] = 'r';l[64] = 'h';l[65] = ' ';l[66] = 'a';l[67] = '<';for (var i = l.length-1; i >= 0; i=i-1) {if (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");else document.write(unescape(l[i]));}</script> test",
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -645,8 +645,8 @@ public function autolinkPopup()
'This is my noreply@codeigniter.com test',
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com" target="_blank">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com" target="_blank">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand Down
18 changes: 9 additions & 9 deletions tests/system/Typography/TypographyTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,11 +64,11 @@ public function testAutoTypographyLineBreaks()
"\n\n" => "\n\n<p>&nbsp;</p>",
"\n\n\n" => "\n\n<p>&nbsp;</p>",
"Line One\n" => "<p>Line One</p>\n\n",
"Line One\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r\n" => "<p>Line One</p>\n\n",
"Line One\r\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\r\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r" => "<p>Line One</p>\n\n",
"Line One\rLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\rLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p>Line Three</p>",
];

Expand All@@ -84,12 +84,12 @@ public function testAutoTypographyReduceLineBreaks()
"\n\n" => "\n\n",
"\n\n\n" => "\n\n\n\n",
"Line One\n" => "<p>Line One</p>\n\n",
"Line One\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r\n" => "<p>Line One</p>\n\n",
"Line One\r\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\r\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r" => "<p>Line One</p>\n\n",
"Line One\rLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p><br />\nLine Three</p>",
"Line One\rLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p><br>\nLine Three</p>",
];

foreach ($strs as $str => $expect) {
Expand DownExpand Up@@ -141,9 +141,9 @@ public function testAutoTypographySpecialCharacters()
public function testNewlinesToHTMLLineBreaksExceptWithinPRE()
{
$strs = [
"Line One\nLine Two" => "Line One<br />\nLine Two",
"Line One\nLine Two" => "Line One<br>\nLine Two",
"<pre>Line One\nLine Two</pre>" => "<pre>Line One\nLine Two</pre>",
"<div>Line One\nLine Two</div>" => "<div>Line One<br />\nLine Two</div>",
"<div>Line One\nLine Two</div>" => "<div>Line One<br>\nLine Two</div>",
];

foreach ($strs as $str => $expect) {
Expand Down
2 changes: 1 addition & 1 deletion tests/system/View/ParserFilterTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,7 +250,7 @@ public function testNL2BR()
$template = '{ value1|nl2br }';

$parser->setData($data);
$this->assertSame("first<br />\nsecond", $parser->renderString($template));
$this->assertSame("first<br>\nsecond", $parser->renderString($template));
}

public function testNumberFormat()
Expand Down
18 changes: 16 additions & 2 deletions user_guide_src/source/changelogs/v4.3.0.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,6 @@ The following methods of the :doc:`Time <../libraries/time>` class had bugs that
Others
------

- **Helper:** Now ``form_helper``, ``html_helper`` and common functions that render HTML elements have been changed to make void HTML elements (e.g. ``<input>``) compatible with HTML5 by default.
- **Helper:** :php:func:`script_tag()` and :php:func:`safe_mailto()` no longer output ``type="text/javascript"`` in ``<script>`` tag.
- **CLI:** The ``spark`` file has been changed due to a change in the processing of Spark commands.
- **CLI:** ``CITestStreamFilter::$buffer = ''`` no longer causes the filter to be registered to listen for streams. Now there
Expand DownExpand Up@@ -231,13 +230,28 @@ Libraries
Helpers and Functions
=====================

- Creation of void HTML elements like ``<input>`` via ``form_helper``, ``html_helper`` or common functions can be configured to exclude or not the solidus character (``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in **app/Config/DocTypes.php** to ``true``.
- Now you can autoload helpers by **app/Config/Autoload.php**.
- Added new Form helper function :php:func:`validation_errors()`, :php:func:`validation_list_errors()` and :php:func:`validation_show_error()` to display Validation Errors.
- You can set the locale to :php:func:`route_to()` if you pass a locale value as the last parameter.
- Added :php:func:`request()` and :php:func:`response()` functions.
- Added :php:func:`decamelize()` function to convert camelCase to snake_case.

HTML5 Compatibility
===================

Creation of void HTML elements like ``<input>`` can be configured to exclude or not the solidus character
(``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in
**app/Config/DocTypes.php**. If you set it to ``true``, HTML5 compatible tags without ``/`` like ``<br>``
will be output.

The following items are affected:

- Typography class: Creation of ``br`` tag
- View Parser: The ``nl2br`` filter
- Form helper
- HTML helper
- Common Functions

Error Handling
==============

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
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: 1 addition & 1 deletion app/Views/welcome_message.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
<title>Welcome to CodeIgniter 4!</title>
<meta name="description" content="The small framework with powerful features">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/png" href="/favicon.ico"/>
<link rel="shortcut icon" type="image/png" href="/favicon.ico">

<!-- STYLES -->

Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Toolbar.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -408,7 +408,7 @@ public function prepare(?RequestInterface $request = null, ?ResponseInterface $r
. 'data-time="' . $time . '" '
. 'src="' . site_url() . '?debugbar"></script>'
. '<script ' . csp_script_nonce() . ' id="debugbar_dynamic_script"></script>'
. '<style type="text/css" ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
. '<style ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
. $kintScript
. PHP_EOL;

Expand Down
4 changes: 2 additions & 2 deletions system/Debug/Toolbar/Views/toolbar.tpl.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@
* @var \CodeIgniter\View\Parser $parser
*/
?>
<style type="text/css">
<style>
<?= preg_replace('#[\r\n\t ]+#', ' ', file_get_contents(__DIR__ . '/toolbar.css')) ?>
</style>

Expand DownExpand Up@@ -264,7 +264,7 @@
<?= $parser->setData($config)->render('_config.tpl') ?>
</div>
</div>
<style type="text/css">
<style>
<?php foreach ($styles as $name => $style): ?>
<?= sprintf(".%s { %s }\n", $name, $style) ?>
<?php endforeach ?>
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -2147,7 +2147,7 @@ private function printDebuggerRaw(): string
*/
protected function setErrorMessage($msg)
{
$this->debugMessage[] = $msg . '<br />';
$this->debugMessage[] = $msg . '<br>';
$this->debugMessageRaw[] = $msg;
}

Expand Down
16 changes: 9 additions & 7 deletions system/Typography/Typography.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ class Typography
public $blockElements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul';

/**
* Elements that should not have <p> and <br /> tags within them.
* Elements that should not have <p> and <br> tags within them.
*
* @var string
*/
Expand DownExpand Up@@ -63,7 +63,7 @@ class Typography
*
* This function converts text, making it typographically correct:
* - Converts double spaces into paragraphs.
* - Converts single line breaks into <br /> tags
* - Converts single line breaks into <br> tags
* - Converts single and double quotes into correctly facing curly quote entities.
* - Converts three dots into ellipsis.
* - Converts double dashes into em-dashes.
Expand DownExpand Up@@ -160,7 +160,7 @@ public function autoTypography(string $str, bool $reduceLinebreaks = false): str
$chunks[$i] .= "\n";
}

// Convert Newlines into <p> and <br /> tags
// Convert Newlines into <p> and <br> tags
$str .= $this->formatNewLines($chunks[$i]);
}

Expand DownExpand Up@@ -275,7 +275,7 @@ public function formatCharacters(string $str): string
/**
* Format Newlines
*
* Converts newline characters into either <p> tags or <br />
* Converts newline characters into either <p> tags or <br>
*/
protected function formatNewLines(string $str): string
{
Expand All@@ -286,8 +286,9 @@ protected function formatNewLines(string $str): string
// Convert two consecutive newlines to paragraphs
$str = str_replace("\n\n", "</p>\n\n<p>", $str);

// Convert single spaces to <br /> tags
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1<br />\\2\\3', $str);
// Convert single spaces to <br> tags
$br = '<br' . _solidus() . '>';
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1' . $br . '\\2\\3', $str);

// Wrap the whole enchilada in enclosing paragraphs
if ($str !== "\n") {
Expand DownExpand Up@@ -323,7 +324,8 @@ public function nl2brExceptPre(string $str): string
$newstr = '';

for ($ex = explode('pre>', $str), $ct = count($ex), $i = 0; $i < $ct; $i++) {
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i]) : $ex[$i];
$xhtml = ! (config('DocTypes')->html5 ?? false);
Comment thread
MGatner marked this conversation as resolved.
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i], $xhtml) : $ex[$i];

if ($ct - 1 !== $i) {
$newstr .= 'pre>';
Expand Down
2 changes: 1 addition & 1 deletion system/View/Filters.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,7 @@ public static function local_currency($value, string $currency, ?string $locale

/**
* Returns a string with all instances of newline character (\n)
* converted to an HTML <br/> tag.
* converted to an HTML <br> tag.
*/
public static function nl2br(string $value): string
{
Expand Down
16 changes: 8 additions & 8 deletions tests/system/Helpers/URLHelper/MiscUrlTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -498,8 +498,8 @@ public function autolinkUrls()
'This is my noreply@codeigniter.com test',
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -547,8 +547,8 @@ public function autolinkEmails()
"This is my <script>var l=new Array();l[0] = '>';l[1] = 'a';l[2] = '/';l[3] = '<';l[4] = '|109';l[5] = '|111';l[6] = '|99';l[7] = '|46';l[8] = '|114';l[9] = '|101';l[10] = '|116';l[11] = '|105';l[12] = '|110';l[13] = '|103';l[14] = '|105';l[15] = '|101';l[16] = '|100';l[17] = '|111';l[18] = '|99';l[19] = '|64';l[20] = '|121';l[21] = '|108';l[22] = '|112';l[23] = '|101';l[24] = '|114';l[25] = '|111';l[26] = '|110';l[27] = '>';l[28] = '\"';l[29] = '|109';l[30] = '|111';l[31] = '|99';l[32] = '|46';l[33] = '|114';l[34] = '|101';l[35] = '|116';l[36] = '|105';l[37] = '|110';l[38] = '|103';l[39] = '|105';l[40] = '|101';l[41] = '|100';l[42] = '|111';l[43] = '|99';l[44] = '|64';l[45] = '|121';l[46] = '|108';l[47] = '|112';l[48] = '|101';l[49] = '|114';l[50] = '|111';l[51] = '|110';l[52] = ':';l[53] = 'o';l[54] = 't';l[55] = 'l';l[56] = 'i';l[57] = 'a';l[58] = 'm';l[59] = '\"';l[60] = '=';l[61] = 'f';l[62] = 'e';l[63] = 'r';l[64] = 'h';l[65] = ' ';l[66] = 'a';l[67] = '<';for (var i = l.length-1; i >= 0; i=i-1) {if (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");else document.write(unescape(l[i]));}</script> test",
],
'test03' => [
'<br />www.google.com',
'<br />www.google.com',
'<br>www.google.com',
'<br>www.google.com',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -596,8 +596,8 @@ public function autolinkBoth()
"This is my <script>var l=new Array();l[0] = '>';l[1] = 'a';l[2] = '/';l[3] = '<';l[4] = '|109';l[5] = '|111';l[6] = '|99';l[7] = '|46';l[8] = '|114';l[9] = '|101';l[10] = '|116';l[11] = '|105';l[12] = '|110';l[13] = '|103';l[14] = '|105';l[15] = '|101';l[16] = '|100';l[17] = '|111';l[18] = '|99';l[19] = '|64';l[20] = '|121';l[21] = '|108';l[22] = '|112';l[23] = '|101';l[24] = '|114';l[25] = '|111';l[26] = '|110';l[27] = '>';l[28] = '\"';l[29] = '|109';l[30] = '|111';l[31] = '|99';l[32] = '|46';l[33] = '|114';l[34] = '|101';l[35] = '|116';l[36] = '|105';l[37] = '|110';l[38] = '|103';l[39] = '|105';l[40] = '|101';l[41] = '|100';l[42] = '|111';l[43] = '|99';l[44] = '|64';l[45] = '|121';l[46] = '|108';l[47] = '|112';l[48] = '|101';l[49] = '|114';l[50] = '|111';l[51] = '|110';l[52] = ':';l[53] = 'o';l[54] = 't';l[55] = 'l';l[56] = 'i';l[57] = 'a';l[58] = 'm';l[59] = '\"';l[60] = '=';l[61] = 'f';l[62] = 'e';l[63] = 'r';l[64] = 'h';l[65] = ' ';l[66] = 'a';l[67] = '<';for (var i = l.length-1; i >= 0; i=i-1) {if (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");else document.write(unescape(l[i]));}</script> test",
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -645,8 +645,8 @@ public function autolinkPopup()
'This is my noreply@codeigniter.com test',
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com" target="_blank">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com" target="_blank">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand Down
18 changes: 9 additions & 9 deletions tests/system/Typography/TypographyTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,11 +64,11 @@ public function testAutoTypographyLineBreaks()
"\n\n" => "\n\n<p>&nbsp;</p>",
"\n\n\n" => "\n\n<p>&nbsp;</p>",
"Line One\n" => "<p>Line One</p>\n\n",
"Line One\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r\n" => "<p>Line One</p>\n\n",
"Line One\r\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\r\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r" => "<p>Line One</p>\n\n",
"Line One\rLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\rLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p>Line Three</p>",
];

Expand All@@ -84,12 +84,12 @@ public function testAutoTypographyReduceLineBreaks()
"\n\n" => "\n\n",
"\n\n\n" => "\n\n\n\n",
"Line One\n" => "<p>Line One</p>\n\n",
"Line One\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r\n" => "<p>Line One</p>\n\n",
"Line One\r\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\r\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r" => "<p>Line One</p>\n\n",
"Line One\rLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p><br />\nLine Three</p>",
"Line One\rLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p><br>\nLine Three</p>",
];

foreach ($strs as $str => $expect) {
Expand DownExpand Up@@ -141,9 +141,9 @@ public function testAutoTypographySpecialCharacters()
public function testNewlinesToHTMLLineBreaksExceptWithinPRE()
{
$strs = [
"Line One\nLine Two" => "Line One<br />\nLine Two",
"Line One\nLine Two" => "Line One<br>\nLine Two",
"<pre>Line One\nLine Two</pre>" => "<pre>Line One\nLine Two</pre>",
"<div>Line One\nLine Two</div>" => "<div>Line One<br />\nLine Two</div>",
"<div>Line One\nLine Two</div>" => "<div>Line One<br>\nLine Two</div>",
];

foreach ($strs as $str => $expect) {
Expand Down
2 changes: 1 addition & 1 deletion tests/system/View/ParserFilterTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,7 +250,7 @@ public function testNL2BR()
$template = '{ value1|nl2br }';

$parser->setData($data);
$this->assertSame("first<br />\nsecond", $parser->renderString($template));
$this->assertSame("first<br>\nsecond", $parser->renderString($template));
}

public function testNumberFormat()
Expand Down
18 changes: 16 additions & 2 deletions user_guide_src/source/changelogs/v4.3.0.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,6 @@ The following methods of the :doc:`Time <../libraries/time>` class had bugs that
Others
------

- **Helper:** Now ``form_helper``, ``html_helper`` and common functions that render HTML elements have been changed to make void HTML elements (e.g. ``<input>``) compatible with HTML5 by default.
- **Helper:** :php:func:`script_tag()` and :php:func:`safe_mailto()` no longer output ``type="text/javascript"`` in ``<script>`` tag.
- **CLI:** The ``spark`` file has been changed due to a change in the processing of Spark commands.
- **CLI:** ``CITestStreamFilter::$buffer = ''`` no longer causes the filter to be registered to listen for streams. Now there
Expand DownExpand Up@@ -231,13 +230,28 @@ Libraries
Helpers and Functions
=====================

- Creation of void HTML elements like ``<input>`` via ``form_helper``, ``html_helper`` or common functions can be configured to exclude or not the solidus character (``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in **app/Config/DocTypes.php** to ``true``.
- Now you can autoload helpers by **app/Config/Autoload.php**.
- Added new Form helper function :php:func:`validation_errors()`, :php:func:`validation_list_errors()` and :php:func:`validation_show_error()` to display Validation Errors.
- You can set the locale to :php:func:`route_to()` if you pass a locale value as the last parameter.
- Added :php:func:`request()` and :php:func:`response()` functions.
- Added :php:func:`decamelize()` function to convert camelCase to snake_case.

HTML5 Compatibility
===================

Creation of void HTML elements like ``<input>`` can be configured to exclude or not the solidus character
(``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in
**app/Config/DocTypes.php**. If you set it to ``true``, HTML5 compatible tags without ``/`` like ``<br>``
will be output.

The following items are affected:

- Typography class: Creation of ``br`` tag
- View Parser: The ``nl2br`` filter
- Form helper
- HTML helper
- Common Functions

Error Handling
==============

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
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: 1 addition & 1 deletion app/Views/welcome_message.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
<title>Welcome to CodeIgniter 4!</title>
<meta name="description" content="The small framework with powerful features">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/png" href="/favicon.ico"/>
<link rel="shortcut icon" type="image/png" href="/favicon.ico">

<!-- STYLES -->

Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Toolbar.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -408,7 +408,7 @@ public function prepare(?RequestInterface $request = null, ?ResponseInterface $r
. 'data-time="' . $time . '" '
. 'src="' . site_url() . '?debugbar"></script>'
. '<script ' . csp_script_nonce() . ' id="debugbar_dynamic_script"></script>'
. '<style type="text/css" ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
. '<style ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
. $kintScript
. PHP_EOL;

Expand Down
4 changes: 2 additions & 2 deletions system/Debug/Toolbar/Views/toolbar.tpl.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@
* @var \CodeIgniter\View\Parser $parser
*/
?>
<style type="text/css">
<style>
<?= preg_replace('#[\r\n\t ]+#', ' ', file_get_contents(__DIR__ . '/toolbar.css')) ?>
</style>

Expand DownExpand Up@@ -264,7 +264,7 @@
<?= $parser->setData($config)->render('_config.tpl') ?>
</div>
</div>
<style type="text/css">
<style>
<?php foreach ($styles as $name => $style): ?>
<?= sprintf(".%s { %s }\n", $name, $style) ?>
<?php endforeach ?>
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -2147,7 +2147,7 @@ private function printDebuggerRaw(): string
*/
protected function setErrorMessage($msg)
{
$this->debugMessage[] = $msg . '<br />';
$this->debugMessage[] = $msg . '<br>';
$this->debugMessageRaw[] = $msg;
}

Expand Down
16 changes: 9 additions & 7 deletions system/Typography/Typography.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ class Typography
public $blockElements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul';

/**
* Elements that should not have <p> and <br /> tags within them.
* Elements that should not have <p> and <br> tags within them.
*
* @var string
*/
Expand DownExpand Up@@ -63,7 +63,7 @@ class Typography
*
* This function converts text, making it typographically correct:
* - Converts double spaces into paragraphs.
* - Converts single line breaks into <br /> tags
* - Converts single line breaks into <br> tags
* - Converts single and double quotes into correctly facing curly quote entities.
* - Converts three dots into ellipsis.
* - Converts double dashes into em-dashes.
Expand DownExpand Up@@ -160,7 +160,7 @@ public function autoTypography(string $str, bool $reduceLinebreaks = false): str
$chunks[$i] .= "\n";
}

// Convert Newlines into <p> and <br /> tags
// Convert Newlines into <p> and <br> tags
$str .= $this->formatNewLines($chunks[$i]);
}

Expand DownExpand Up@@ -275,7 +275,7 @@ public function formatCharacters(string $str): string
/**
* Format Newlines
*
* Converts newline characters into either <p> tags or <br />
* Converts newline characters into either <p> tags or <br>
*/
protected function formatNewLines(string $str): string
{
Expand All@@ -286,8 +286,9 @@ protected function formatNewLines(string $str): string
// Convert two consecutive newlines to paragraphs
$str = str_replace("\n\n", "</p>\n\n<p>", $str);

// Convert single spaces to <br /> tags
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1<br />\\2\\3', $str);
// Convert single spaces to <br> tags
$br = '<br' . _solidus() . '>';
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1' . $br . '\\2\\3', $str);

// Wrap the whole enchilada in enclosing paragraphs
if ($str !== "\n") {
Expand DownExpand Up@@ -323,7 +324,8 @@ public function nl2brExceptPre(string $str): string
$newstr = '';

for ($ex = explode('pre>', $str), $ct = count($ex), $i = 0; $i < $ct; $i++) {
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i]) : $ex[$i];
$xhtml = ! (config('DocTypes')->html5 ?? false);
Comment thread
MGatner marked this conversation as resolved.
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i], $xhtml) : $ex[$i];

if ($ct - 1 !== $i) {
$newstr .= 'pre>';
Expand Down
2 changes: 1 addition & 1 deletion system/View/Filters.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,7 @@ public static function local_currency($value, string $currency, ?string $locale

/**
* Returns a string with all instances of newline character (\n)
* converted to an HTML <br/> tag.
* converted to an HTML <br> tag.
*/
public static function nl2br(string $value): string
{
Expand Down
16 changes: 8 additions & 8 deletions tests/system/Helpers/URLHelper/MiscUrlTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -498,8 +498,8 @@ public function autolinkUrls()
'This is my noreply@codeigniter.com test',
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -547,8 +547,8 @@ public function autolinkEmails()
"This is my <script>var l=new Array();l[0] = '>';l[1] = 'a';l[2] = '/';l[3] = '<';l[4] = '|109';l[5] = '|111';l[6] = '|99';l[7] = '|46';l[8] = '|114';l[9] = '|101';l[10] = '|116';l[11] = '|105';l[12] = '|110';l[13] = '|103';l[14] = '|105';l[15] = '|101';l[16] = '|100';l[17] = '|111';l[18] = '|99';l[19] = '|64';l[20] = '|121';l[21] = '|108';l[22] = '|112';l[23] = '|101';l[24] = '|114';l[25] = '|111';l[26] = '|110';l[27] = '>';l[28] = '\"';l[29] = '|109';l[30] = '|111';l[31] = '|99';l[32] = '|46';l[33] = '|114';l[34] = '|101';l[35] = '|116';l[36] = '|105';l[37] = '|110';l[38] = '|103';l[39] = '|105';l[40] = '|101';l[41] = '|100';l[42] = '|111';l[43] = '|99';l[44] = '|64';l[45] = '|121';l[46] = '|108';l[47] = '|112';l[48] = '|101';l[49] = '|114';l[50] = '|111';l[51] = '|110';l[52] = ':';l[53] = 'o';l[54] = 't';l[55] = 'l';l[56] = 'i';l[57] = 'a';l[58] = 'm';l[59] = '\"';l[60] = '=';l[61] = 'f';l[62] = 'e';l[63] = 'r';l[64] = 'h';l[65] = ' ';l[66] = 'a';l[67] = '<';for (var i = l.length-1; i >= 0; i=i-1) {if (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");else document.write(unescape(l[i]));}</script> test",
],
'test03' => [
'<br />www.google.com',
'<br />www.google.com',
'<br>www.google.com',
'<br>www.google.com',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -596,8 +596,8 @@ public function autolinkBoth()
"This is my <script>var l=new Array();l[0] = '>';l[1] = 'a';l[2] = '/';l[3] = '<';l[4] = '|109';l[5] = '|111';l[6] = '|99';l[7] = '|46';l[8] = '|114';l[9] = '|101';l[10] = '|116';l[11] = '|105';l[12] = '|110';l[13] = '|103';l[14] = '|105';l[15] = '|101';l[16] = '|100';l[17] = '|111';l[18] = '|99';l[19] = '|64';l[20] = '|121';l[21] = '|108';l[22] = '|112';l[23] = '|101';l[24] = '|114';l[25] = '|111';l[26] = '|110';l[27] = '>';l[28] = '\"';l[29] = '|109';l[30] = '|111';l[31] = '|99';l[32] = '|46';l[33] = '|114';l[34] = '|101';l[35] = '|116';l[36] = '|105';l[37] = '|110';l[38] = '|103';l[39] = '|105';l[40] = '|101';l[41] = '|100';l[42] = '|111';l[43] = '|99';l[44] = '|64';l[45] = '|121';l[46] = '|108';l[47] = '|112';l[48] = '|101';l[49] = '|114';l[50] = '|111';l[51] = '|110';l[52] = ':';l[53] = 'o';l[54] = 't';l[55] = 'l';l[56] = 'i';l[57] = 'a';l[58] = 'm';l[59] = '\"';l[60] = '=';l[61] = 'f';l[62] = 'e';l[63] = 'r';l[64] = 'h';l[65] = ' ';l[66] = 'a';l[67] = '<';for (var i = l.length-1; i >= 0; i=i-1) {if (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");else document.write(unescape(l[i]));}</script> test",
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -645,8 +645,8 @@ public function autolinkPopup()
'This is my noreply@codeigniter.com test',
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com" target="_blank">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com" target="_blank">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand Down
18 changes: 9 additions & 9 deletions tests/system/Typography/TypographyTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,11 +64,11 @@ public function testAutoTypographyLineBreaks()
"\n\n" => "\n\n<p>&nbsp;</p>",
"\n\n\n" => "\n\n<p>&nbsp;</p>",
"Line One\n" => "<p>Line One</p>\n\n",
"Line One\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r\n" => "<p>Line One</p>\n\n",
"Line One\r\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\r\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r" => "<p>Line One</p>\n\n",
"Line One\rLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\rLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p>Line Three</p>",
];

Expand All@@ -84,12 +84,12 @@ public function testAutoTypographyReduceLineBreaks()
"\n\n" => "\n\n",
"\n\n\n" => "\n\n\n\n",
"Line One\n" => "<p>Line One</p>\n\n",
"Line One\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r\n" => "<p>Line One</p>\n\n",
"Line One\r\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\r\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r" => "<p>Line One</p>\n\n",
"Line One\rLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p><br />\nLine Three</p>",
"Line One\rLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p><br>\nLine Three</p>",
];

foreach ($strs as $str => $expect) {
Expand DownExpand Up@@ -141,9 +141,9 @@ public function testAutoTypographySpecialCharacters()
public function testNewlinesToHTMLLineBreaksExceptWithinPRE()
{
$strs = [
"Line One\nLine Two" => "Line One<br />\nLine Two",
"Line One\nLine Two" => "Line One<br>\nLine Two",
"<pre>Line One\nLine Two</pre>" => "<pre>Line One\nLine Two</pre>",
"<div>Line One\nLine Two</div>" => "<div>Line One<br />\nLine Two</div>",
"<div>Line One\nLine Two</div>" => "<div>Line One<br>\nLine Two</div>",
];

foreach ($strs as $str => $expect) {
Expand Down
2 changes: 1 addition & 1 deletion tests/system/View/ParserFilterTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,7 +250,7 @@ public function testNL2BR()
$template = '{ value1|nl2br }';

$parser->setData($data);
$this->assertSame("first<br />\nsecond", $parser->renderString($template));
$this->assertSame("first<br>\nsecond", $parser->renderString($template));
}

public function testNumberFormat()
Expand Down
18 changes: 16 additions & 2 deletions user_guide_src/source/changelogs/v4.3.0.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,6 @@ The following methods of the :doc:`Time <../libraries/time>` class had bugs that
Others
------

- **Helper:** Now ``form_helper``, ``html_helper`` and common functions that render HTML elements have been changed to make void HTML elements (e.g. ``<input>``) compatible with HTML5 by default.
- **Helper:** :php:func:`script_tag()` and :php:func:`safe_mailto()` no longer output ``type="text/javascript"`` in ``<script>`` tag.
- **CLI:** The ``spark`` file has been changed due to a change in the processing of Spark commands.
- **CLI:** ``CITestStreamFilter::$buffer = ''`` no longer causes the filter to be registered to listen for streams. Now there
Expand DownExpand Up@@ -231,13 +230,28 @@ Libraries
Helpers and Functions
=====================

- Creation of void HTML elements like ``<input>`` via ``form_helper``, ``html_helper`` or common functions can be configured to exclude or not the solidus character (``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in **app/Config/DocTypes.php** to ``true``.
- Now you can autoload helpers by **app/Config/Autoload.php**.
- Added new Form helper function :php:func:`validation_errors()`, :php:func:`validation_list_errors()` and :php:func:`validation_show_error()` to display Validation Errors.
- You can set the locale to :php:func:`route_to()` if you pass a locale value as the last parameter.
- Added :php:func:`request()` and :php:func:`response()` functions.
- Added :php:func:`decamelize()` function to convert camelCase to snake_case.

HTML5 Compatibility
===================

Creation of void HTML elements like ``<input>`` can be configured to exclude or not the solidus character
(``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in
**app/Config/DocTypes.php**. If you set it to ``true``, HTML5 compatible tags without ``/`` like ``<br>``
will be output.

The following items are affected:

- Typography class: Creation of ``br`` tag
- View Parser: The ``nl2br`` filter
- Form helper
- HTML helper
- Common Functions

Error Handling
==============

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
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: 1 addition & 1 deletion app/Views/welcome_message.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
<title>Welcome to CodeIgniter 4!</title>
<meta name="description" content="The small framework with powerful features">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/png" href="/favicon.ico"/>
<link rel="shortcut icon" type="image/png" href="/favicon.ico">

<!-- STYLES -->

Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Toolbar.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -408,7 +408,7 @@ public function prepare(?RequestInterface $request = null, ?ResponseInterface $r
. 'data-time="' . $time . '" '
. 'src="' . site_url() . '?debugbar"></script>'
. '<script ' . csp_script_nonce() . ' id="debugbar_dynamic_script"></script>'
. '<style type="text/css" ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
. '<style ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
. $kintScript
. PHP_EOL;

Expand Down
4 changes: 2 additions & 2 deletions system/Debug/Toolbar/Views/toolbar.tpl.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@
* @var \CodeIgniter\View\Parser $parser
*/
?>
<style type="text/css">
<style>
<?= preg_replace('#[\r\n\t ]+#', ' ', file_get_contents(__DIR__ . '/toolbar.css')) ?>
</style>

Expand DownExpand Up@@ -264,7 +264,7 @@
<?= $parser->setData($config)->render('_config.tpl') ?>
</div>
</div>
<style type="text/css">
<style>
<?php foreach ($styles as $name => $style): ?>
<?= sprintf(".%s { %s }\n", $name, $style) ?>
<?php endforeach ?>
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -2147,7 +2147,7 @@ private function printDebuggerRaw(): string
*/
protected function setErrorMessage($msg)
{
$this->debugMessage[] = $msg . '<br />';
$this->debugMessage[] = $msg . '<br>';
$this->debugMessageRaw[] = $msg;
}

Expand Down
16 changes: 9 additions & 7 deletions system/Typography/Typography.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ class Typography
public $blockElements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul';

/**
* Elements that should not have <p> and <br /> tags within them.
* Elements that should not have <p> and <br> tags within them.
*
* @var string
*/
Expand DownExpand Up@@ -63,7 +63,7 @@ class Typography
*
* This function converts text, making it typographically correct:
* - Converts double spaces into paragraphs.
* - Converts single line breaks into <br /> tags
* - Converts single line breaks into <br> tags
* - Converts single and double quotes into correctly facing curly quote entities.
* - Converts three dots into ellipsis.
* - Converts double dashes into em-dashes.
Expand DownExpand Up@@ -160,7 +160,7 @@ public function autoTypography(string $str, bool $reduceLinebreaks = false): str
$chunks[$i] .= "\n";
}

// Convert Newlines into <p> and <br /> tags
// Convert Newlines into <p> and <br> tags
$str .= $this->formatNewLines($chunks[$i]);
}

Expand DownExpand Up@@ -275,7 +275,7 @@ public function formatCharacters(string $str): string
/**
* Format Newlines
*
* Converts newline characters into either <p> tags or <br />
* Converts newline characters into either <p> tags or <br>
*/
protected function formatNewLines(string $str): string
{
Expand All@@ -286,8 +286,9 @@ protected function formatNewLines(string $str): string
// Convert two consecutive newlines to paragraphs
$str = str_replace("\n\n", "</p>\n\n<p>", $str);

// Convert single spaces to <br /> tags
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1<br />\\2\\3', $str);
// Convert single spaces to <br> tags
$br = '<br' . _solidus() . '>';
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1' . $br . '\\2\\3', $str);

// Wrap the whole enchilada in enclosing paragraphs
if ($str !== "\n") {
Expand DownExpand Up@@ -323,7 +324,8 @@ public function nl2brExceptPre(string $str): string
$newstr = '';

for ($ex = explode('pre>', $str), $ct = count($ex), $i = 0; $i < $ct; $i++) {
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i]) : $ex[$i];
$xhtml = ! (config('DocTypes')->html5 ?? false);
Comment thread
MGatner marked this conversation as resolved.
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i], $xhtml) : $ex[$i];

if ($ct - 1 !== $i) {
$newstr .= 'pre>';
Expand Down
2 changes: 1 addition & 1 deletion system/View/Filters.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,7 @@ public static function local_currency($value, string $currency, ?string $locale

/**
* Returns a string with all instances of newline character (\n)
* converted to an HTML <br/> tag.
* converted to an HTML <br> tag.
*/
public static function nl2br(string $value): string
{
Expand Down
16 changes: 8 additions & 8 deletions tests/system/Helpers/URLHelper/MiscUrlTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -498,8 +498,8 @@ public function autolinkUrls()
'This is my noreply@codeigniter.com test',
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -547,8 +547,8 @@ public function autolinkEmails()
"This is my <script>var l=new Array();l[0] = '>';l[1] = 'a';l[2] = '/';l[3] = '<';l[4] = '|109';l[5] = '|111';l[6] = '|99';l[7] = '|46';l[8] = '|114';l[9] = '|101';l[10] = '|116';l[11] = '|105';l[12] = '|110';l[13] = '|103';l[14] = '|105';l[15] = '|101';l[16] = '|100';l[17] = '|111';l[18] = '|99';l[19] = '|64';l[20] = '|121';l[21] = '|108';l[22] = '|112';l[23] = '|101';l[24] = '|114';l[25] = '|111';l[26] = '|110';l[27] = '>';l[28] = '\"';l[29] = '|109';l[30] = '|111';l[31] = '|99';l[32] = '|46';l[33] = '|114';l[34] = '|101';l[35] = '|116';l[36] = '|105';l[37] = '|110';l[38] = '|103';l[39] = '|105';l[40] = '|101';l[41] = '|100';l[42] = '|111';l[43] = '|99';l[44] = '|64';l[45] = '|121';l[46] = '|108';l[47] = '|112';l[48] = '|101';l[49] = '|114';l[50] = '|111';l[51] = '|110';l[52] = ':';l[53] = 'o';l[54] = 't';l[55] = 'l';l[56] = 'i';l[57] = 'a';l[58] = 'm';l[59] = '\"';l[60] = '=';l[61] = 'f';l[62] = 'e';l[63] = 'r';l[64] = 'h';l[65] = ' ';l[66] = 'a';l[67] = '<';for (var i = l.length-1; i >= 0; i=i-1) {if (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");else document.write(unescape(l[i]));}</script> test",
],
'test03' => [
'<br />www.google.com',
'<br />www.google.com',
'<br>www.google.com',
'<br>www.google.com',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -596,8 +596,8 @@ public function autolinkBoth()
"This is my <script>var l=new Array();l[0] = '>';l[1] = 'a';l[2] = '/';l[3] = '<';l[4] = '|109';l[5] = '|111';l[6] = '|99';l[7] = '|46';l[8] = '|114';l[9] = '|101';l[10] = '|116';l[11] = '|105';l[12] = '|110';l[13] = '|103';l[14] = '|105';l[15] = '|101';l[16] = '|100';l[17] = '|111';l[18] = '|99';l[19] = '|64';l[20] = '|121';l[21] = '|108';l[22] = '|112';l[23] = '|101';l[24] = '|114';l[25] = '|111';l[26] = '|110';l[27] = '>';l[28] = '\"';l[29] = '|109';l[30] = '|111';l[31] = '|99';l[32] = '|46';l[33] = '|114';l[34] = '|101';l[35] = '|116';l[36] = '|105';l[37] = '|110';l[38] = '|103';l[39] = '|105';l[40] = '|101';l[41] = '|100';l[42] = '|111';l[43] = '|99';l[44] = '|64';l[45] = '|121';l[46] = '|108';l[47] = '|112';l[48] = '|101';l[49] = '|114';l[50] = '|111';l[51] = '|110';l[52] = ':';l[53] = 'o';l[54] = 't';l[55] = 'l';l[56] = 'i';l[57] = 'a';l[58] = 'm';l[59] = '\"';l[60] = '=';l[61] = 'f';l[62] = 'e';l[63] = 'r';l[64] = 'h';l[65] = ' ';l[66] = 'a';l[67] = '<';for (var i = l.length-1; i >= 0; i=i-1) {if (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");else document.write(unescape(l[i]));}</script> test",
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -645,8 +645,8 @@ public function autolinkPopup()
'This is my noreply@codeigniter.com test',
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com" target="_blank">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com" target="_blank">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand Down
18 changes: 9 additions & 9 deletions tests/system/Typography/TypographyTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,11 +64,11 @@ public function testAutoTypographyLineBreaks()
"\n\n" => "\n\n<p>&nbsp;</p>",
"\n\n\n" => "\n\n<p>&nbsp;</p>",
"Line One\n" => "<p>Line One</p>\n\n",
"Line One\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r\n" => "<p>Line One</p>\n\n",
"Line One\r\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\r\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r" => "<p>Line One</p>\n\n",
"Line One\rLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\rLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p>Line Three</p>",
];

Expand All@@ -84,12 +84,12 @@ public function testAutoTypographyReduceLineBreaks()
"\n\n" => "\n\n",
"\n\n\n" => "\n\n\n\n",
"Line One\n" => "<p>Line One</p>\n\n",
"Line One\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r\n" => "<p>Line One</p>\n\n",
"Line One\r\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\r\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r" => "<p>Line One</p>\n\n",
"Line One\rLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p><br />\nLine Three</p>",
"Line One\rLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p><br>\nLine Three</p>",
];

foreach ($strs as $str => $expect) {
Expand DownExpand Up@@ -141,9 +141,9 @@ public function testAutoTypographySpecialCharacters()
public function testNewlinesToHTMLLineBreaksExceptWithinPRE()
{
$strs = [
"Line One\nLine Two" => "Line One<br />\nLine Two",
"Line One\nLine Two" => "Line One<br>\nLine Two",
"<pre>Line One\nLine Two</pre>" => "<pre>Line One\nLine Two</pre>",
"<div>Line One\nLine Two</div>" => "<div>Line One<br />\nLine Two</div>",
"<div>Line One\nLine Two</div>" => "<div>Line One<br>\nLine Two</div>",
];

foreach ($strs as $str => $expect) {
Expand Down
2 changes: 1 addition & 1 deletion tests/system/View/ParserFilterTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,7 +250,7 @@ public function testNL2BR()
$template = '{ value1|nl2br }';

$parser->setData($data);
$this->assertSame("first<br />\nsecond", $parser->renderString($template));
$this->assertSame("first<br>\nsecond", $parser->renderString($template));
}

public function testNumberFormat()
Expand Down
18 changes: 16 additions & 2 deletions user_guide_src/source/changelogs/v4.3.0.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,6 @@ The following methods of the :doc:`Time <../libraries/time>` class had bugs that
Others
------

- **Helper:** Now ``form_helper``, ``html_helper`` and common functions that render HTML elements have been changed to make void HTML elements (e.g. ``<input>``) compatible with HTML5 by default.
- **Helper:** :php:func:`script_tag()` and :php:func:`safe_mailto()` no longer output ``type="text/javascript"`` in ``<script>`` tag.
- **CLI:** The ``spark`` file has been changed due to a change in the processing of Spark commands.
- **CLI:** ``CITestStreamFilter::$buffer = ''`` no longer causes the filter to be registered to listen for streams. Now there
Expand DownExpand Up@@ -231,13 +230,28 @@ Libraries
Helpers and Functions
=====================

- Creation of void HTML elements like ``<input>`` via ``form_helper``, ``html_helper`` or common functions can be configured to exclude or not the solidus character (``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in **app/Config/DocTypes.php** to ``true``.
- Now you can autoload helpers by **app/Config/Autoload.php**.
- Added new Form helper function :php:func:`validation_errors()`, :php:func:`validation_list_errors()` and :php:func:`validation_show_error()` to display Validation Errors.
- You can set the locale to :php:func:`route_to()` if you pass a locale value as the last parameter.
- Added :php:func:`request()` and :php:func:`response()` functions.
- Added :php:func:`decamelize()` function to convert camelCase to snake_case.

HTML5 Compatibility
===================

Creation of void HTML elements like ``<input>`` can be configured to exclude or not the solidus character
(``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in
**app/Config/DocTypes.php**. If you set it to ``true``, HTML5 compatible tags without ``/`` like ``<br>``
will be output.

The following items are affected:

- Typography class: Creation of ``br`` tag
- View Parser: The ``nl2br`` filter
- Form helper
- HTML helper
- Common Functions

Error Handling
==============

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
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: 1 addition & 1 deletion app/Views/welcome_message.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
<title>Welcome to CodeIgniter 4!</title>
<meta name="description" content="The small framework with powerful features">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/png" href="/favicon.ico"/>
<link rel="shortcut icon" type="image/png" href="/favicon.ico">

<!-- STYLES -->

Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Toolbar.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -408,7 +408,7 @@ public function prepare(?RequestInterface $request = null, ?ResponseInterface $r
. 'data-time="' . $time . '" '
. 'src="' . site_url() . '?debugbar"></script>'
. '<script ' . csp_script_nonce() . ' id="debugbar_dynamic_script"></script>'
. '<style type="text/css" ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
. '<style ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
. $kintScript
. PHP_EOL;

Expand Down
4 changes: 2 additions & 2 deletions system/Debug/Toolbar/Views/toolbar.tpl.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@
* @var \CodeIgniter\View\Parser $parser
*/
?>
<style type="text/css">
<style>
<?= preg_replace('#[\r\n\t ]+#', ' ', file_get_contents(__DIR__ . '/toolbar.css')) ?>
</style>

Expand DownExpand Up@@ -264,7 +264,7 @@
<?= $parser->setData($config)->render('_config.tpl') ?>
</div>
</div>
<style type="text/css">
<style>
<?php foreach ($styles as $name => $style): ?>
<?= sprintf(".%s { %s }\n", $name, $style) ?>
<?php endforeach ?>
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -2147,7 +2147,7 @@ private function printDebuggerRaw(): string
*/
protected function setErrorMessage($msg)
{
$this->debugMessage[] = $msg . '<br />';
$this->debugMessage[] = $msg . '<br>';
$this->debugMessageRaw[] = $msg;
}

Expand Down
16 changes: 9 additions & 7 deletions system/Typography/Typography.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ class Typography
public $blockElements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul';

/**
* Elements that should not have <p> and <br /> tags within them.
* Elements that should not have <p> and <br> tags within them.
*
* @var string
*/
Expand DownExpand Up@@ -63,7 +63,7 @@ class Typography
*
* This function converts text, making it typographically correct:
* - Converts double spaces into paragraphs.
* - Converts single line breaks into <br /> tags
* - Converts single line breaks into <br> tags
* - Converts single and double quotes into correctly facing curly quote entities.
* - Converts three dots into ellipsis.
* - Converts double dashes into em-dashes.
Expand DownExpand Up@@ -160,7 +160,7 @@ public function autoTypography(string $str, bool $reduceLinebreaks = false): str
$chunks[$i] .= "\n";
}

// Convert Newlines into <p> and <br /> tags
// Convert Newlines into <p> and <br> tags
$str .= $this->formatNewLines($chunks[$i]);
}

Expand DownExpand Up@@ -275,7 +275,7 @@ public function formatCharacters(string $str): string
/**
* Format Newlines
*
* Converts newline characters into either <p> tags or <br />
* Converts newline characters into either <p> tags or <br>
*/
protected function formatNewLines(string $str): string
{
Expand All@@ -286,8 +286,9 @@ protected function formatNewLines(string $str): string
// Convert two consecutive newlines to paragraphs
$str = str_replace("\n\n", "</p>\n\n<p>", $str);

// Convert single spaces to <br /> tags
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1<br />\\2\\3', $str);
// Convert single spaces to <br> tags
$br = '<br' . _solidus() . '>';
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1' . $br . '\\2\\3', $str);

// Wrap the whole enchilada in enclosing paragraphs
if ($str !== "\n") {
Expand DownExpand Up@@ -323,7 +324,8 @@ public function nl2brExceptPre(string $str): string
$newstr = '';

for ($ex = explode('pre>', $str), $ct = count($ex), $i = 0; $i < $ct; $i++) {
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i]) : $ex[$i];
$xhtml = ! (config('DocTypes')->html5 ?? false);
Comment thread
MGatner marked this conversation as resolved.
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i], $xhtml) : $ex[$i];

if ($ct - 1 !== $i) {
$newstr .= 'pre>';
Expand Down
2 changes: 1 addition & 1 deletion system/View/Filters.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,7 @@ public static function local_currency($value, string $currency, ?string $locale

/**
* Returns a string with all instances of newline character (\n)
* converted to an HTML <br/> tag.
* converted to an HTML <br> tag.
*/
public static function nl2br(string $value): string
{
Expand Down
16 changes: 8 additions & 8 deletions tests/system/Helpers/URLHelper/MiscUrlTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -498,8 +498,8 @@ public function autolinkUrls()
'This is my noreply@codeigniter.com test',
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -547,8 +547,8 @@ public function autolinkEmails()
"This is my <script>var l=new Array();l[0] = '>';l[1] = 'a';l[2] = '/';l[3] = '<';l[4] = '|109';l[5] = '|111';l[6] = '|99';l[7] = '|46';l[8] = '|114';l[9] = '|101';l[10] = '|116';l[11] = '|105';l[12] = '|110';l[13] = '|103';l[14] = '|105';l[15] = '|101';l[16] = '|100';l[17] = '|111';l[18] = '|99';l[19] = '|64';l[20] = '|121';l[21] = '|108';l[22] = '|112';l[23] = '|101';l[24] = '|114';l[25] = '|111';l[26] = '|110';l[27] = '>';l[28] = '\"';l[29] = '|109';l[30] = '|111';l[31] = '|99';l[32] = '|46';l[33] = '|114';l[34] = '|101';l[35] = '|116';l[36] = '|105';l[37] = '|110';l[38] = '|103';l[39] = '|105';l[40] = '|101';l[41] = '|100';l[42] = '|111';l[43] = '|99';l[44] = '|64';l[45] = '|121';l[46] = '|108';l[47] = '|112';l[48] = '|101';l[49] = '|114';l[50] = '|111';l[51] = '|110';l[52] = ':';l[53] = 'o';l[54] = 't';l[55] = 'l';l[56] = 'i';l[57] = 'a';l[58] = 'm';l[59] = '\"';l[60] = '=';l[61] = 'f';l[62] = 'e';l[63] = 'r';l[64] = 'h';l[65] = ' ';l[66] = 'a';l[67] = '<';for (var i = l.length-1; i >= 0; i=i-1) {if (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");else document.write(unescape(l[i]));}</script> test",
],
'test03' => [
'<br />www.google.com',
'<br />www.google.com',
'<br>www.google.com',
'<br>www.google.com',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -596,8 +596,8 @@ public function autolinkBoth()
"This is my <script>var l=new Array();l[0] = '>';l[1] = 'a';l[2] = '/';l[3] = '<';l[4] = '|109';l[5] = '|111';l[6] = '|99';l[7] = '|46';l[8] = '|114';l[9] = '|101';l[10] = '|116';l[11] = '|105';l[12] = '|110';l[13] = '|103';l[14] = '|105';l[15] = '|101';l[16] = '|100';l[17] = '|111';l[18] = '|99';l[19] = '|64';l[20] = '|121';l[21] = '|108';l[22] = '|112';l[23] = '|101';l[24] = '|114';l[25] = '|111';l[26] = '|110';l[27] = '>';l[28] = '\"';l[29] = '|109';l[30] = '|111';l[31] = '|99';l[32] = '|46';l[33] = '|114';l[34] = '|101';l[35] = '|116';l[36] = '|105';l[37] = '|110';l[38] = '|103';l[39] = '|105';l[40] = '|101';l[41] = '|100';l[42] = '|111';l[43] = '|99';l[44] = '|64';l[45] = '|121';l[46] = '|108';l[47] = '|112';l[48] = '|101';l[49] = '|114';l[50] = '|111';l[51] = '|110';l[52] = ':';l[53] = 'o';l[54] = 't';l[55] = 'l';l[56] = 'i';l[57] = 'a';l[58] = 'm';l[59] = '\"';l[60] = '=';l[61] = 'f';l[62] = 'e';l[63] = 'r';l[64] = 'h';l[65] = ' ';l[66] = 'a';l[67] = '<';for (var i = l.length-1; i >= 0; i=i-1) {if (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");else document.write(unescape(l[i]));}</script> test",
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -645,8 +645,8 @@ public function autolinkPopup()
'This is my noreply@codeigniter.com test',
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com" target="_blank">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com" target="_blank">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand Down
18 changes: 9 additions & 9 deletions tests/system/Typography/TypographyTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,11 +64,11 @@ public function testAutoTypographyLineBreaks()
"\n\n" => "\n\n<p>&nbsp;</p>",
"\n\n\n" => "\n\n<p>&nbsp;</p>",
"Line One\n" => "<p>Line One</p>\n\n",
"Line One\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r\n" => "<p>Line One</p>\n\n",
"Line One\r\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\r\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r" => "<p>Line One</p>\n\n",
"Line One\rLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\rLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p>Line Three</p>",
];

Expand All@@ -84,12 +84,12 @@ public function testAutoTypographyReduceLineBreaks()
"\n\n" => "\n\n",
"\n\n\n" => "\n\n\n\n",
"Line One\n" => "<p>Line One</p>\n\n",
"Line One\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r\n" => "<p>Line One</p>\n\n",
"Line One\r\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\r\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r" => "<p>Line One</p>\n\n",
"Line One\rLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p><br />\nLine Three</p>",
"Line One\rLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p><br>\nLine Three</p>",
];

foreach ($strs as $str => $expect) {
Expand DownExpand Up@@ -141,9 +141,9 @@ public function testAutoTypographySpecialCharacters()
public function testNewlinesToHTMLLineBreaksExceptWithinPRE()
{
$strs = [
"Line One\nLine Two" => "Line One<br />\nLine Two",
"Line One\nLine Two" => "Line One<br>\nLine Two",
"<pre>Line One\nLine Two</pre>" => "<pre>Line One\nLine Two</pre>",
"<div>Line One\nLine Two</div>" => "<div>Line One<br />\nLine Two</div>",
"<div>Line One\nLine Two</div>" => "<div>Line One<br>\nLine Two</div>",
];

foreach ($strs as $str => $expect) {
Expand Down
2 changes: 1 addition & 1 deletion tests/system/View/ParserFilterTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,7 +250,7 @@ public function testNL2BR()
$template = '{ value1|nl2br }';

$parser->setData($data);
$this->assertSame("first<br />\nsecond", $parser->renderString($template));
$this->assertSame("first<br>\nsecond", $parser->renderString($template));
}

public function testNumberFormat()
Expand Down
18 changes: 16 additions & 2 deletions user_guide_src/source/changelogs/v4.3.0.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,6 @@ The following methods of the :doc:`Time <../libraries/time>` class had bugs that
Others
------

- **Helper:** Now ``form_helper``, ``html_helper`` and common functions that render HTML elements have been changed to make void HTML elements (e.g. ``<input>``) compatible with HTML5 by default.
- **Helper:** :php:func:`script_tag()` and :php:func:`safe_mailto()` no longer output ``type="text/javascript"`` in ``<script>`` tag.
- **CLI:** The ``spark`` file has been changed due to a change in the processing of Spark commands.
- **CLI:** ``CITestStreamFilter::$buffer = ''`` no longer causes the filter to be registered to listen for streams. Now there
Expand DownExpand Up@@ -231,13 +230,28 @@ Libraries
Helpers and Functions
=====================

- Creation of void HTML elements like ``<input>`` via ``form_helper``, ``html_helper`` or common functions can be configured to exclude or not the solidus character (``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in **app/Config/DocTypes.php** to ``true``.
- Now you can autoload helpers by **app/Config/Autoload.php**.
- Added new Form helper function :php:func:`validation_errors()`, :php:func:`validation_list_errors()` and :php:func:`validation_show_error()` to display Validation Errors.
- You can set the locale to :php:func:`route_to()` if you pass a locale value as the last parameter.
- Added :php:func:`request()` and :php:func:`response()` functions.
- Added :php:func:`decamelize()` function to convert camelCase to snake_case.

HTML5 Compatibility
===================

Creation of void HTML elements like ``<input>`` can be configured to exclude or not the solidus character
(``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in
**app/Config/DocTypes.php**. If you set it to ``true``, HTML5 compatible tags without ``/`` like ``<br>``
will be output.

The following items are affected:

- Typography class: Creation of ``br`` tag
- View Parser: The ``nl2br`` filter
- Form helper
- HTML helper
- Common Functions

Error Handling
==============

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
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: 1 addition & 1 deletion app/Views/welcome_message.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
<title>Welcome to CodeIgniter 4!</title>
<meta name="description" content="The small framework with powerful features">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/png" href="/favicon.ico"/>
<link rel="shortcut icon" type="image/png" href="/favicon.ico">

<!-- STYLES -->

Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Toolbar.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -408,7 +408,7 @@ public function prepare(?RequestInterface $request = null, ?ResponseInterface $r
. 'data-time="' . $time . '" '
. 'src="' . site_url() . '?debugbar"></script>'
. '<script ' . csp_script_nonce() . ' id="debugbar_dynamic_script"></script>'
. '<style type="text/css" ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
. '<style ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
. $kintScript
. PHP_EOL;

Expand Down
4 changes: 2 additions & 2 deletions system/Debug/Toolbar/Views/toolbar.tpl.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@
* @var \CodeIgniter\View\Parser $parser
*/
?>
<style type="text/css">
<style>
<?= preg_replace('#[\r\n\t ]+#', ' ', file_get_contents(__DIR__ . '/toolbar.css')) ?>
</style>

Expand DownExpand Up@@ -264,7 +264,7 @@
<?= $parser->setData($config)->render('_config.tpl') ?>
</div>
</div>
<style type="text/css">
<style>
<?php foreach ($styles as $name => $style): ?>
<?= sprintf(".%s { %s }\n", $name, $style) ?>
<?php endforeach ?>
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -2147,7 +2147,7 @@ private function printDebuggerRaw(): string
*/
protected function setErrorMessage($msg)
{
$this->debugMessage[] = $msg . '<br />';
$this->debugMessage[] = $msg . '<br>';
$this->debugMessageRaw[] = $msg;
}

Expand Down
16 changes: 9 additions & 7 deletions system/Typography/Typography.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ class Typography
public $blockElements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul';

/**
* Elements that should not have <p> and <br /> tags within them.
* Elements that should not have <p> and <br> tags within them.
*
* @var string
*/
Expand DownExpand Up@@ -63,7 +63,7 @@ class Typography
*
* This function converts text, making it typographically correct:
* - Converts double spaces into paragraphs.
* - Converts single line breaks into <br /> tags
* - Converts single line breaks into <br> tags
* - Converts single and double quotes into correctly facing curly quote entities.
* - Converts three dots into ellipsis.
* - Converts double dashes into em-dashes.
Expand DownExpand Up@@ -160,7 +160,7 @@ public function autoTypography(string $str, bool $reduceLinebreaks = false): str
$chunks[$i] .= "\n";
}

// Convert Newlines into <p> and <br /> tags
// Convert Newlines into <p> and <br> tags
$str .= $this->formatNewLines($chunks[$i]);
}

Expand DownExpand Up@@ -275,7 +275,7 @@ public function formatCharacters(string $str): string
/**
* Format Newlines
*
* Converts newline characters into either <p> tags or <br />
* Converts newline characters into either <p> tags or <br>
*/
protected function formatNewLines(string $str): string
{
Expand All@@ -286,8 +286,9 @@ protected function formatNewLines(string $str): string
// Convert two consecutive newlines to paragraphs
$str = str_replace("\n\n", "</p>\n\n<p>", $str);

// Convert single spaces to <br /> tags
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1<br />\\2\\3', $str);
// Convert single spaces to <br> tags
$br = '<br' . _solidus() . '>';
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1' . $br . '\\2\\3', $str);

// Wrap the whole enchilada in enclosing paragraphs
if ($str !== "\n") {
Expand DownExpand Up@@ -323,7 +324,8 @@ public function nl2brExceptPre(string $str): string
$newstr = '';

for ($ex = explode('pre>', $str), $ct = count($ex), $i = 0; $i < $ct; $i++) {
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i]) : $ex[$i];
$xhtml = ! (config('DocTypes')->html5 ?? false);
Comment thread
MGatner marked this conversation as resolved.
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i], $xhtml) : $ex[$i];

if ($ct - 1 !== $i) {
$newstr .= 'pre>';
Expand Down
2 changes: 1 addition & 1 deletion system/View/Filters.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,7 @@ public static function local_currency($value, string $currency, ?string $locale

/**
* Returns a string with all instances of newline character (\n)
* converted to an HTML <br/> tag.
* converted to an HTML <br> tag.
*/
public static function nl2br(string $value): string
{
Expand Down
16 changes: 8 additions & 8 deletions tests/system/Helpers/URLHelper/MiscUrlTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -498,8 +498,8 @@ public function autolinkUrls()
'This is my noreply@codeigniter.com test',
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -547,8 +547,8 @@ public function autolinkEmails()
"This is my <script>var l=new Array();l[0] = '>';l[1] = 'a';l[2] = '/';l[3] = '<';l[4] = '|109';l[5] = '|111';l[6] = '|99';l[7] = '|46';l[8] = '|114';l[9] = '|101';l[10] = '|116';l[11] = '|105';l[12] = '|110';l[13] = '|103';l[14] = '|105';l[15] = '|101';l[16] = '|100';l[17] = '|111';l[18] = '|99';l[19] = '|64';l[20] = '|121';l[21] = '|108';l[22] = '|112';l[23] = '|101';l[24] = '|114';l[25] = '|111';l[26] = '|110';l[27] = '>';l[28] = '\"';l[29] = '|109';l[30] = '|111';l[31] = '|99';l[32] = '|46';l[33] = '|114';l[34] = '|101';l[35] = '|116';l[36] = '|105';l[37] = '|110';l[38] = '|103';l[39] = '|105';l[40] = '|101';l[41] = '|100';l[42] = '|111';l[43] = '|99';l[44] = '|64';l[45] = '|121';l[46] = '|108';l[47] = '|112';l[48] = '|101';l[49] = '|114';l[50] = '|111';l[51] = '|110';l[52] = ':';l[53] = 'o';l[54] = 't';l[55] = 'l';l[56] = 'i';l[57] = 'a';l[58] = 'm';l[59] = '\"';l[60] = '=';l[61] = 'f';l[62] = 'e';l[63] = 'r';l[64] = 'h';l[65] = ' ';l[66] = 'a';l[67] = '<';for (var i = l.length-1; i >= 0; i=i-1) {if (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");else document.write(unescape(l[i]));}</script> test",
],
'test03' => [
'<br />www.google.com',
'<br />www.google.com',
'<br>www.google.com',
'<br>www.google.com',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -596,8 +596,8 @@ public function autolinkBoth()
"This is my <script>var l=new Array();l[0] = '>';l[1] = 'a';l[2] = '/';l[3] = '<';l[4] = '|109';l[5] = '|111';l[6] = '|99';l[7] = '|46';l[8] = '|114';l[9] = '|101';l[10] = '|116';l[11] = '|105';l[12] = '|110';l[13] = '|103';l[14] = '|105';l[15] = '|101';l[16] = '|100';l[17] = '|111';l[18] = '|99';l[19] = '|64';l[20] = '|121';l[21] = '|108';l[22] = '|112';l[23] = '|101';l[24] = '|114';l[25] = '|111';l[26] = '|110';l[27] = '>';l[28] = '\"';l[29] = '|109';l[30] = '|111';l[31] = '|99';l[32] = '|46';l[33] = '|114';l[34] = '|101';l[35] = '|116';l[36] = '|105';l[37] = '|110';l[38] = '|103';l[39] = '|105';l[40] = '|101';l[41] = '|100';l[42] = '|111';l[43] = '|99';l[44] = '|64';l[45] = '|121';l[46] = '|108';l[47] = '|112';l[48] = '|101';l[49] = '|114';l[50] = '|111';l[51] = '|110';l[52] = ':';l[53] = 'o';l[54] = 't';l[55] = 'l';l[56] = 'i';l[57] = 'a';l[58] = 'm';l[59] = '\"';l[60] = '=';l[61] = 'f';l[62] = 'e';l[63] = 'r';l[64] = 'h';l[65] = ' ';l[66] = 'a';l[67] = '<';for (var i = l.length-1; i >= 0; i=i-1) {if (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");else document.write(unescape(l[i]));}</script> test",
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -645,8 +645,8 @@ public function autolinkPopup()
'This is my noreply@codeigniter.com test',
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com" target="_blank">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com" target="_blank">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand Down
18 changes: 9 additions & 9 deletions tests/system/Typography/TypographyTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,11 +64,11 @@ public function testAutoTypographyLineBreaks()
"\n\n" => "\n\n<p>&nbsp;</p>",
"\n\n\n" => "\n\n<p>&nbsp;</p>",
"Line One\n" => "<p>Line One</p>\n\n",
"Line One\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r\n" => "<p>Line One</p>\n\n",
"Line One\r\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\r\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r" => "<p>Line One</p>\n\n",
"Line One\rLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\rLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p>Line Three</p>",
];

Expand All@@ -84,12 +84,12 @@ public function testAutoTypographyReduceLineBreaks()
"\n\n" => "\n\n",
"\n\n\n" => "\n\n\n\n",
"Line One\n" => "<p>Line One</p>\n\n",
"Line One\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r\n" => "<p>Line One</p>\n\n",
"Line One\r\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\r\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r" => "<p>Line One</p>\n\n",
"Line One\rLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p><br />\nLine Three</p>",
"Line One\rLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p><br>\nLine Three</p>",
];

foreach ($strs as $str => $expect) {
Expand DownExpand Up@@ -141,9 +141,9 @@ public function testAutoTypographySpecialCharacters()
public function testNewlinesToHTMLLineBreaksExceptWithinPRE()
{
$strs = [
"Line One\nLine Two" => "Line One<br />\nLine Two",
"Line One\nLine Two" => "Line One<br>\nLine Two",
"<pre>Line One\nLine Two</pre>" => "<pre>Line One\nLine Two</pre>",
"<div>Line One\nLine Two</div>" => "<div>Line One<br />\nLine Two</div>",
"<div>Line One\nLine Two</div>" => "<div>Line One<br>\nLine Two</div>",
];

foreach ($strs as $str => $expect) {
Expand Down
2 changes: 1 addition & 1 deletion tests/system/View/ParserFilterTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,7 +250,7 @@ public function testNL2BR()
$template = '{ value1|nl2br }';

$parser->setData($data);
$this->assertSame("first<br />\nsecond", $parser->renderString($template));
$this->assertSame("first<br>\nsecond", $parser->renderString($template));
}

public function testNumberFormat()
Expand Down
18 changes: 16 additions & 2 deletions user_guide_src/source/changelogs/v4.3.0.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,6 @@ The following methods of the :doc:`Time <../libraries/time>` class had bugs that
Others
------

- **Helper:** Now ``form_helper``, ``html_helper`` and common functions that render HTML elements have been changed to make void HTML elements (e.g. ``<input>``) compatible with HTML5 by default.
- **Helper:** :php:func:`script_tag()` and :php:func:`safe_mailto()` no longer output ``type="text/javascript"`` in ``<script>`` tag.
- **CLI:** The ``spark`` file has been changed due to a change in the processing of Spark commands.
- **CLI:** ``CITestStreamFilter::$buffer = ''`` no longer causes the filter to be registered to listen for streams. Now there
Expand DownExpand Up@@ -231,13 +230,28 @@ Libraries
Helpers and Functions
=====================

- Creation of void HTML elements like ``<input>`` via ``form_helper``, ``html_helper`` or common functions can be configured to exclude or not the solidus character (``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in **app/Config/DocTypes.php** to ``true``.
- Now you can autoload helpers by **app/Config/Autoload.php**.
- Added new Form helper function :php:func:`validation_errors()`, :php:func:`validation_list_errors()` and :php:func:`validation_show_error()` to display Validation Errors.
- You can set the locale to :php:func:`route_to()` if you pass a locale value as the last parameter.
- Added :php:func:`request()` and :php:func:`response()` functions.
- Added :php:func:`decamelize()` function to convert camelCase to snake_case.

HTML5 Compatibility
===================

Creation of void HTML elements like ``<input>`` can be configured to exclude or not the solidus character
(``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in
**app/Config/DocTypes.php**. If you set it to ``true``, HTML5 compatible tags without ``/`` like ``<br>``
will be output.

The following items are affected:

- Typography class: Creation of ``br`` tag
- View Parser: The ``nl2br`` filter
- Form helper
- HTML helper
- Common Functions

Error Handling
==============

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
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: 1 addition & 1 deletion app/Views/welcome_message.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
<title>Welcome to CodeIgniter 4!</title>
<meta name="description" content="The small framework with powerful features">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/png" href="/favicon.ico"/>
<link rel="shortcut icon" type="image/png" href="/favicon.ico">

<!-- STYLES -->

Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Toolbar.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -408,7 +408,7 @@ public function prepare(?RequestInterface $request = null, ?ResponseInterface $r
. 'data-time="' . $time . '" '
. 'src="' . site_url() . '?debugbar"></script>'
. '<script ' . csp_script_nonce() . ' id="debugbar_dynamic_script"></script>'
. '<style type="text/css" ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
. '<style ' . csp_style_nonce() . ' id="debugbar_dynamic_style"></style>'
. $kintScript
. PHP_EOL;

Expand Down
4 changes: 2 additions & 2 deletions system/Debug/Toolbar/Views/toolbar.tpl.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@
* @var \CodeIgniter\View\Parser $parser
*/
?>
<style type="text/css">
<style>
<?= preg_replace('#[\r\n\t ]+#', ' ', file_get_contents(__DIR__ . '/toolbar.css')) ?>
</style>

Expand DownExpand Up@@ -264,7 +264,7 @@
<?= $parser->setData($config)->render('_config.tpl') ?>
</div>
</div>
<style type="text/css">
<style>
<?php foreach ($styles as $name => $style): ?>
<?= sprintf(".%s { %s }\n", $name, $style) ?>
<?php endforeach ?>
Expand Down
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -2147,7 +2147,7 @@ private function printDebuggerRaw(): string
*/
protected function setErrorMessage($msg)
{
$this->debugMessage[] = $msg . '<br />';
$this->debugMessage[] = $msg . '<br>';
$this->debugMessageRaw[] = $msg;
}

Expand Down
16 changes: 9 additions & 7 deletions system/Typography/Typography.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ class Typography
public $blockElements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul';

/**
* Elements that should not have <p> and <br /> tags within them.
* Elements that should not have <p> and <br> tags within them.
*
* @var string
*/
Expand DownExpand Up@@ -63,7 +63,7 @@ class Typography
*
* This function converts text, making it typographically correct:
* - Converts double spaces into paragraphs.
* - Converts single line breaks into <br /> tags
* - Converts single line breaks into <br> tags
* - Converts single and double quotes into correctly facing curly quote entities.
* - Converts three dots into ellipsis.
* - Converts double dashes into em-dashes.
Expand DownExpand Up@@ -160,7 +160,7 @@ public function autoTypography(string $str, bool $reduceLinebreaks = false): str
$chunks[$i] .= "\n";
}

// Convert Newlines into <p> and <br /> tags
// Convert Newlines into <p> and <br> tags
$str .= $this->formatNewLines($chunks[$i]);
}

Expand DownExpand Up@@ -275,7 +275,7 @@ public function formatCharacters(string $str): string
/**
* Format Newlines
*
* Converts newline characters into either <p> tags or <br />
* Converts newline characters into either <p> tags or <br>
*/
protected function formatNewLines(string $str): string
{
Expand All@@ -286,8 +286,9 @@ protected function formatNewLines(string $str): string
// Convert two consecutive newlines to paragraphs
$str = str_replace("\n\n", "</p>\n\n<p>", $str);

// Convert single spaces to <br /> tags
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1<br />\\2\\3', $str);
// Convert single spaces to <br> tags
$br = '<br' . _solidus() . '>';
$str = preg_replace("/([^\n])(\n)([^\n])/", '\\1' . $br . '\\2\\3', $str);

// Wrap the whole enchilada in enclosing paragraphs
if ($str !== "\n") {
Expand DownExpand Up@@ -323,7 +324,8 @@ public function nl2brExceptPre(string $str): string
$newstr = '';

for ($ex = explode('pre>', $str), $ct = count($ex), $i = 0; $i < $ct; $i++) {
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i]) : $ex[$i];
$xhtml = ! (config('DocTypes')->html5 ?? false);
Comment thread
MGatner marked this conversation as resolved.
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i], $xhtml) : $ex[$i];

if ($ct - 1 !== $i) {
$newstr .= 'pre>';
Expand Down
2 changes: 1 addition & 1 deletion system/View/Filters.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,7 +182,7 @@ public static function local_currency($value, string $currency, ?string $locale

/**
* Returns a string with all instances of newline character (\n)
* converted to an HTML <br/> tag.
* converted to an HTML <br> tag.
*/
public static function nl2br(string $value): string
{
Expand Down
16 changes: 8 additions & 8 deletions tests/system/Helpers/URLHelper/MiscUrlTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -498,8 +498,8 @@ public function autolinkUrls()
'This is my noreply@codeigniter.com test',
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -547,8 +547,8 @@ public function autolinkEmails()
"This is my <script>var l=new Array();l[0] = '>';l[1] = 'a';l[2] = '/';l[3] = '<';l[4] = '|109';l[5] = '|111';l[6] = '|99';l[7] = '|46';l[8] = '|114';l[9] = '|101';l[10] = '|116';l[11] = '|105';l[12] = '|110';l[13] = '|103';l[14] = '|105';l[15] = '|101';l[16] = '|100';l[17] = '|111';l[18] = '|99';l[19] = '|64';l[20] = '|121';l[21] = '|108';l[22] = '|112';l[23] = '|101';l[24] = '|114';l[25] = '|111';l[26] = '|110';l[27] = '>';l[28] = '\"';l[29] = '|109';l[30] = '|111';l[31] = '|99';l[32] = '|46';l[33] = '|114';l[34] = '|101';l[35] = '|116';l[36] = '|105';l[37] = '|110';l[38] = '|103';l[39] = '|105';l[40] = '|101';l[41] = '|100';l[42] = '|111';l[43] = '|99';l[44] = '|64';l[45] = '|121';l[46] = '|108';l[47] = '|112';l[48] = '|101';l[49] = '|114';l[50] = '|111';l[51] = '|110';l[52] = ':';l[53] = 'o';l[54] = 't';l[55] = 'l';l[56] = 'i';l[57] = 'a';l[58] = 'm';l[59] = '\"';l[60] = '=';l[61] = 'f';l[62] = 'e';l[63] = 'r';l[64] = 'h';l[65] = ' ';l[66] = 'a';l[67] = '<';for (var i = l.length-1; i >= 0; i=i-1) {if (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");else document.write(unescape(l[i]));}</script> test",
],
'test03' => [
'<br />www.google.com',
'<br />www.google.com',
'<br>www.google.com',
'<br>www.google.com',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -596,8 +596,8 @@ public function autolinkBoth()
"This is my <script>var l=new Array();l[0] = '>';l[1] = 'a';l[2] = '/';l[3] = '<';l[4] = '|109';l[5] = '|111';l[6] = '|99';l[7] = '|46';l[8] = '|114';l[9] = '|101';l[10] = '|116';l[11] = '|105';l[12] = '|110';l[13] = '|103';l[14] = '|105';l[15] = '|101';l[16] = '|100';l[17] = '|111';l[18] = '|99';l[19] = '|64';l[20] = '|121';l[21] = '|108';l[22] = '|112';l[23] = '|101';l[24] = '|114';l[25] = '|111';l[26] = '|110';l[27] = '>';l[28] = '\"';l[29] = '|109';l[30] = '|111';l[31] = '|99';l[32] = '|46';l[33] = '|114';l[34] = '|101';l[35] = '|116';l[36] = '|105';l[37] = '|110';l[38] = '|103';l[39] = '|105';l[40] = '|101';l[41] = '|100';l[42] = '|111';l[43] = '|99';l[44] = '|64';l[45] = '|121';l[46] = '|108';l[47] = '|112';l[48] = '|101';l[49] = '|114';l[50] = '|111';l[51] = '|110';l[52] = ':';l[53] = 'o';l[54] = 't';l[55] = 'l';l[56] = 'i';l[57] = 'a';l[58] = 'm';l[59] = '\"';l[60] = '=';l[61] = 'f';l[62] = 'e';l[63] = 'r';l[64] = 'h';l[65] = ' ';l[66] = 'a';l[67] = '<';for (var i = l.length-1; i >= 0; i=i-1) {if (l[i].substring(0, 1) === '|') document.write(\"&#\"+unescape(l[i].substring(1))+\";\");else document.write(unescape(l[i]));}</script> test",
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand DownExpand Up@@ -645,8 +645,8 @@ public function autolinkPopup()
'This is my noreply@codeigniter.com test',
],
'test03' => [
'<br />www.google.com',
'<br /><a href="http://www.google.com" target="_blank">www.google.com</a>',
'<br>www.google.com',
'<br><a href="http://www.google.com" target="_blank">www.google.com</a>',
],
'test04' => [
'Download CodeIgniter at www.codeigniter.com. Period test.',
Expand Down
18 changes: 9 additions & 9 deletions tests/system/Typography/TypographyTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,11 +64,11 @@ public function testAutoTypographyLineBreaks()
"\n\n" => "\n\n<p>&nbsp;</p>",
"\n\n\n" => "\n\n<p>&nbsp;</p>",
"Line One\n" => "<p>Line One</p>\n\n",
"Line One\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r\n" => "<p>Line One</p>\n\n",
"Line One\r\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\r\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r" => "<p>Line One</p>\n\n",
"Line One\rLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\rLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p>Line Three</p>",
];

Expand All@@ -84,12 +84,12 @@ public function testAutoTypographyReduceLineBreaks()
"\n\n" => "\n\n",
"\n\n\n" => "\n\n\n\n",
"Line One\n" => "<p>Line One</p>\n\n",
"Line One\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r\n" => "<p>Line One</p>\n\n",
"Line One\r\nLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\r\nLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\r" => "<p>Line One</p>\n\n",
"Line One\rLine Two" => "<p>Line One<br />\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p><br />\nLine Three</p>",
"Line One\rLine Two" => "<p>Line One<br>\nLine Two</p>",
"Line One\n\nLine Two\n\n\nLine Three" => "<p>Line One</p>\n\n<p>Line Two</p>\n\n<p><br>\nLine Three</p>",
];

foreach ($strs as $str => $expect) {
Expand DownExpand Up@@ -141,9 +141,9 @@ public function testAutoTypographySpecialCharacters()
public function testNewlinesToHTMLLineBreaksExceptWithinPRE()
{
$strs = [
"Line One\nLine Two" => "Line One<br />\nLine Two",
"Line One\nLine Two" => "Line One<br>\nLine Two",
"<pre>Line One\nLine Two</pre>" => "<pre>Line One\nLine Two</pre>",
"<div>Line One\nLine Two</div>" => "<div>Line One<br />\nLine Two</div>",
"<div>Line One\nLine Two</div>" => "<div>Line One<br>\nLine Two</div>",
];

foreach ($strs as $str => $expect) {
Expand Down
2 changes: 1 addition & 1 deletion tests/system/View/ParserFilterTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,7 +250,7 @@ public function testNL2BR()
$template = '{ value1|nl2br }';

$parser->setData($data);
$this->assertSame("first<br />\nsecond", $parser->renderString($template));
$this->assertSame("first<br>\nsecond", $parser->renderString($template));
}

public function testNumberFormat()
Expand Down
18 changes: 16 additions & 2 deletions user_guide_src/source/changelogs/v4.3.0.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,7 +61,6 @@ The following methods of the :doc:`Time <../libraries/time>` class had bugs that
Others
------

- **Helper:** Now ``form_helper``, ``html_helper`` and common functions that render HTML elements have been changed to make void HTML elements (e.g. ``<input>``) compatible with HTML5 by default.
- **Helper:** :php:func:`script_tag()` and :php:func:`safe_mailto()` no longer output ``type="text/javascript"`` in ``<script>`` tag.
- **CLI:** The ``spark`` file has been changed due to a change in the processing of Spark commands.
- **CLI:** ``CITestStreamFilter::$buffer = ''`` no longer causes the filter to be registered to listen for streams. Now there
Expand DownExpand Up@@ -231,13 +230,28 @@ Libraries
Helpers and Functions
=====================

- Creation of void HTML elements like ``<input>`` via ``form_helper``, ``html_helper`` or common functions can be configured to exclude or not the solidus character (``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in **app/Config/DocTypes.php** to ``true``.
- Now you can autoload helpers by **app/Config/Autoload.php**.
- Added new Form helper function :php:func:`validation_errors()`, :php:func:`validation_list_errors()` and :php:func:`validation_show_error()` to display Validation Errors.
- You can set the locale to :php:func:`route_to()` if you pass a locale value as the last parameter.
- Added :php:func:`request()` and :php:func:`response()` functions.
- Added :php:func:`decamelize()` function to convert camelCase to snake_case.

HTML5 Compatibility
===================

Creation of void HTML elements like ``<input>`` can be configured to exclude or not the solidus character
(``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in
**app/Config/DocTypes.php**. If you set it to ``true``, HTML5 compatible tags without ``/`` like ``<br>``
will be output.

The following items are affected:

- Typography class: Creation of ``br`` tag
- View Parser: The ``nl2br`` filter
- Form helper
- HTML helper
- Common Functions

Error Handling
==============

Expand Down