Skip to content

Commit

Permalink
Merge branch 'release/2.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ediamin committed Jan 13, 2025
2 parents 6af1c24 + 43d8306 commit 2d80373
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 11 deletions.
2 changes: 1 addition & 1 deletion includes/WPConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class WPConsole {
*
* @var string
*/
public $version = '2.5.0';
public $version = '2.5.1';

/**
* Minimum PHP version required
Expand Down
1 change: 1 addition & 0 deletions lib/overrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Common overrides for all PHP versions.
*/

require_once __DIR__ . '/overrides/psy/psysh/src/VarDumper/Dumper.php';
require_once __DIR__ . '/overrides/psy/psysh/src/Output/ShellOutput.php';
require_once __DIR__ . '/overrides/psy/psysh/src/Output/Theme.php';
require_once __DIR__ . '/overrides/psy/psysh/src/Shell.php';
2 changes: 2 additions & 0 deletions lib/overrides/psy/psysh/src/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,8 @@ public function writeStdout(string $out, int $phase = \PHP_OUTPUT_HANDLER_END)

// Incremental flush
if ($out !== '' && !$isCleaning) {
// @see Issue: https://wordpress.org/support/topic/html-output-display-issue/.
$out = esc_html($out);
$this->output->write($out, false, OutputInterface::OUTPUT_RAW);
$this->outputWantsNewline = (\substr($out, -1) !== "\n");
$this->stdoutBuffer .= $out;
Expand Down
111 changes: 111 additions & 0 deletions lib/overrides/psy/psysh/src/VarDumper/Dumper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php

/*
* This file is part of Psy Shell.
*
* (c) 2012-2023 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Psy\VarDumper;

use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\VarDumper\Cloner\Cursor;
use Symfony\Component\VarDumper\Dumper\CliDumper;

/**
* A PsySH-specialized CliDumper.
*/
class Dumper extends CliDumper
{
private $formatter;
private $forceArrayIndexes;

protected static $onlyControlCharsRx = '/^[\x00-\x1F\x7F]+$/';
protected static $controlCharsRx = '/([\x00-\x1F\x7F]+)/';
protected static $controlCharsMap = [
"\0" => '\0',
"\t" => '\t',
"\n" => '\n',
"\v" => '\v',
"\f" => '\f',
"\r" => '\r',
"\033" => '\e',
];

public function __construct(OutputFormatter $formatter, $forceArrayIndexes = false)
{
$this->formatter = $formatter;
$this->forceArrayIndexes = $forceArrayIndexes;
parent::__construct();
$this->setColors(false);
}

/**
* {@inheritdoc}
*/
public function enterHash(Cursor $cursor, $type, $class, $hasChild)
{
if (Cursor::HASH_INDEXED === $type || Cursor::HASH_ASSOC === $type) {
$class = 0;
}
parent::enterHash($cursor, $type, $class, $hasChild);
}

/**
* {@inheritdoc}
*/
protected function dumpKey(Cursor $cursor)
{
if ($this->forceArrayIndexes || Cursor::HASH_INDEXED !== $cursor->hashType) {
parent::dumpKey($cursor);
}
}

protected function style($style, $value, $attr = []): string
{
if ('ref' === $style) {
$value = \strtr($value, '@', '#');
}

$styled = '';
$map = self::$controlCharsMap;
$cchr = $this->styles['cchr'];

$chunks = \preg_split(self::$controlCharsRx, $value, -1, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE);
foreach ($chunks as $chunk) {
if (\preg_match(self::$onlyControlCharsRx, $chunk)) {
$chars = '';
$i = 0;
do {
$chars .= isset($map[$chunk[$i]]) ? $map[$chunk[$i]] : \sprintf('\x%02X', \ord($chunk[$i]));
} while (isset($chunk[++$i]));

$chars = $this->formatter->escape($chars);
$styled .= "<{$cchr}>{$chars}</{$cchr}>";
} else {
// @see Issue: https://wordpress.org/support/topic/html-output-display-issue/.
$chunk = esc_html($chunk);
$styled .= $this->formatter->escape($chunk);
}
}

$style = $this->styles[$style];

return "<{$style}>{$styled}</{$style}>";
}

/**
* {@inheritdoc}
*/
protected function dumpLine($depth, $endOfValue = false)
{
if ($endOfValue && 0 < $depth) {
$this->line .= ',';
}
$this->line = $this->formatter->format($this->line);
parent::dumpLine($depth, $endOfValue);
}
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wp-console",
"version": "2.5.0",
"version": "2.5.1",
"description": "An in-browser PHP console for WordPress powered by PsySH",
"author": "Edi Amin <[email protected]>",
"license": "GPL-3.0",
Expand Down Expand Up @@ -48,7 +48,7 @@
"shelljs": "0.8.5"
},
"scripts": {
"env:start": "wp-env start",
"env:start": "wp-env start --xdebug=debug",
"env:stop": "wp-env stop",
"dev": "wp-scripts start",
"build": "wp-scripts build",
Expand Down
12 changes: 9 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
=== WP Console - WordPress PHP Console powered by PsySH ===
Contributors: ediamin
Tags: console, repl, browser, psysh, shell, dump
Tags: repl, browser, shell, dump, autocomplete
Requires at least: 5.3.12
Tested up to: 6.7
Tested up to: 6.7.1
Requires PHP: 7.4
Stable tag: 2.5.0
Stable tag: 2.5.1
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -39,6 +39,9 @@ To begin using the plugin, follow these steps:
== Security Concern ==
WP Console explicitly verifies the presence of the `manage_options` permission to render the user interface and execute various functions. However, it's important to note that this plugin is not intended for use on a production server.

== Other Plugin ==
Working with the block or the block editor? Checkout [CSS Class Manager](https://wordpress.org/plugins/css-class-manager/) – An advanced autocomplete additional css class control for your blocks.

== Screenshots ==

1. Basic input output
Expand All @@ -56,6 +59,9 @@ WP Console explicitly verifies the presence of the `manage_options` permission t

== Changelog ==

2.5.1 - January 13, 2025
* Prevent HTML rendering in console output.

2.5.0 - November 17, 2024
* Breaking: Dropped support for PHP 5.6. The minimum PHP requirement is now 7.4.
* Refactored the dependency loading process for improved performance and maintainability.
Expand Down
5 changes: 5 additions & 0 deletions src/Console/Output.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { __ } from '@wordpress/i18n';
import { Fragment } from '@wordpress/element';
import { Tooltip } from '@wordpress/components';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
Expand All @@ -18,6 +19,10 @@ const toolTipPlacement = wpConsole.wp_version.gte_6_4
function formatOutput( output ) {
// Strip all html tags.
output = output.replace( /(<([^>]+)>)/gi, '' );

// Decode HTML entities in string type data.
output = decodeEntities( output );

// Replace new line
output = output.replace( //gi, '\n' );

Expand Down
7 changes: 4 additions & 3 deletions src/scss/_symfony-dump.scss
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ pre.sf-dump span {
display: inline;
}

pre.sf-dump .sf-dump-compact {
display: none;
}
// Reveal the nested structure of the dumped data.
// pre.sf-dump .sf-dump-compact {
// display: none;
// }

pre.sf-dump abbr {
text-decoration: none;
Expand Down
2 changes: 1 addition & 1 deletion wp-console.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WP Console
* Plugin URI: https://github.com/ediamin/wp-console
* Description: An in-browser PHP console for WordPress powered by PsySH
* Version: 2.5.0
* Version: 2.5.1
* Author: Edi Amin
* Author URI: https://github.com/ediamin
* Text Domain: wp-console
Expand Down

0 comments on commit 2d80373

Please sign in to comment.