Skip to content

Commit

Permalink
Moves hard-coded tab substitute string into a constant
Browse files Browse the repository at this point in the history
Also changes the content of the tab substitute string to something better and unique.
Signed-off-by: Jon Stovell <[email protected]>
  • Loading branch information
Sesquipedalian committed Dec 6, 2024
1 parent 731e67a commit 1683803
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Sources/Actions/Admin/ErrorLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,11 @@ public function view(): void
} elseif ($this->filter['variable'] == 'url') {
Utils::$context['filter']['value']['html'] = '\'' . strtr(Utils::htmlspecialchars((str_starts_with($this->filter['value']['sql'], '?') ? Config::$scripturl : '') . $this->filter['value']['sql']), ['\\_' => '_']) . '\'';
} elseif ($this->filter['variable'] == 'message') {
Utils::$context['filter']['value']['html'] = '\'' . strtr(Utils::htmlspecialchars($this->filter['value']['sql']), ["\n" => '<br>', '&lt;br /&gt;' => '<br>', "\t" => '&nbsp;&nbsp;&nbsp;', '\\_' => '_', '\\%' => '%', '\\\\' => '\\']) . '\'';
Utils::$context['filter']['value']['html'] = '\'' . strtr(Utils::htmlspecialchars($this->filter['value']['sql']), ["\n" => '<br>', '&lt;br /&gt;' => '<br>', "\t" => Utils::TAB_SUBSTITUTE, '\\_' => '_', '\\%' => '%', '\\\\' => '\\']) . '\'';

Utils::$context['filter']['value']['html'] = preg_replace('~&amp;lt;span class=&amp;quot;remove&amp;quot;&amp;gt;(.+?)&amp;lt;/span&amp;gt;~', '$1', Utils::$context['filter']['value']['html']);
} elseif ($this->filter['variable'] == 'error_type') {
Utils::$context['filter']['value']['html'] = '\'' . strtr(Utils::htmlspecialchars($this->filter['value']['sql']), ["\n" => '<br>', '&lt;br /&gt;' => '<br>', "\t" => '&nbsp;&nbsp;&nbsp;', '\\_' => '_', '\\%' => '%', '\\\\' => '\\']) . '\'';
Utils::$context['filter']['value']['html'] = '\'' . strtr(Utils::htmlspecialchars($this->filter['value']['sql']), ["\n" => '<br>', '&lt;br /&gt;' => '<br>', "\t" => Utils::TAB_SUBSTITUTE, '\\_' => '_', '\\%' => '%', '\\\\' => '\\']) . '\'';
} else {
Utils::$context['filter']['value']['html'] = &$this->filter['value']['sql'];
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/BBCodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2648,7 +2648,7 @@ protected function parseMessage(): void
// Restore any placeholders
$data = strtr($data, $this->placeholders);

$data = strtr($data, ["\t" => '&nbsp;&nbsp;&nbsp;']);
$data = strtr($data, ["\t" => Utils::TAB_SUBSTITUTE]);

// If it wasn't changed, no copying or other boring stuff has to happen!
if ($data != substr($this->message, $this->last_pos, $this->pos - $this->last_pos)) {
Expand Down
7 changes: 7 additions & 0 deletions Sources/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ class Utils
*/
public const ENT_NBSP = '&(?' . '>nbsp|#(?' . '>x0*A0|0*160));';

/**
* @var string
*
* Used to force the browser not to collapse tabs.
*/
public const TAB_SUBSTITUTE = "\u{200B}\u{2007}\u{2007}\u{2007}\u{2007}\u{200B}";

/**************************
* Public static properties
**************************/
Expand Down

0 comments on commit 1683803

Please sign in to comment.