Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[VarDumper] Disable links for IntelliJ platform #49274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public function apply(string $text)
{
if (null === $this->handlesHrefGracefully) {
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR')
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100);
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100)
&& !isset($_SERVER['IDEA_INITIAL_DIRECTORY']);
}

if (null !== $this->href && $this->handlesHrefGracefully) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,14 @@ public function testFormatterHasStyles()
/**
* @dataProvider provideDecoratedAndNonDecoratedOutput
*/
public function testNotDecoratedFormatter(string $input, string $expectedNonDecoratedOutput, string $expectedDecoratedOutput, string $terminalEmulator = 'foo')
{
public function testNotDecoratedFormatterOnJediTermEmulator(
string $input,
string $expectedNonDecoratedOutput,
string $expectedDecoratedOutput,
bool $shouldBeJediTerm = false
) {
$terminalEmulator = $shouldBeJediTerm ? 'JetBrains-JediTerm' : 'Unknown';

$prevTerminalEmulator = getenv('TERMINAL_EMULATOR');
putenv('TERMINAL_EMULATOR='.$terminalEmulator);

Expand All @@ -258,6 +264,39 @@ public function testNotDecoratedFormatter(string $input, string $expectedNonDeco
}
}

/**
* @dataProvider provideDecoratedAndNonDecoratedOutput
*/
public function testNotDecoratedFormatterOnIDEALikeEnvironment(
string $input,
string $expectedNonDecoratedOutput,
string $expectedDecoratedOutput,
bool $expectsIDEALikeTerminal = false
) {
// Backup previous env variable
$previousValue = $_SERVER['IDEA_INITIAL_DIRECTORY'] ?? null;
$hasPreviousValue = \array_key_exists('IDEA_INITIAL_DIRECTORY', $_SERVER);

if ($expectsIDEALikeTerminal) {
$_SERVER['IDEA_INITIAL_DIRECTORY'] = __DIR__;
} elseif ($hasPreviousValue) {
// Forcibly remove the variable because the test runner may contain it
unset($_SERVER['IDEA_INITIAL_DIRECTORY']);
}

try {
$this->assertEquals($expectedDecoratedOutput, (new OutputFormatter(true))->format($input));
$this->assertEquals($expectedNonDecoratedOutput, (new OutputFormatter(false))->format($input));
} finally {
// Rollback previous env state
if ($hasPreviousValue) {
$_SERVER['IDEA_INITIAL_DIRECTORY'] = $previousValue;
} else {
unset($_SERVER['IDEA_INITIAL_DIRECTORY']);
}
}
}

public static function provideDecoratedAndNonDecoratedOutput()
{
return [
Expand All @@ -268,7 +307,7 @@ public static function provideDecoratedAndNonDecoratedOutput()
['<fg=red>some text with inline style</>', 'some text with inline style', "\033[31msome text with inline style\033[39m"],
['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', "\033]8;;idea://open/?file=/path/SomeFile.php&line=12\033\\some URL\033]8;;\033\\"],
['<href=https://example.com/\<woohoo\>>some URL with \<woohoo\></>', 'some URL with <woohoo>', "\033]8;;https://example.com/<woohoo>\033\\some URL with <woohoo>\033]8;;\033\\"],
['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', 'some URL', 'JetBrains-JediTerm'],
['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', 'some URL', true],
];
}

Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/VarDumper/Dumper/CliDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ protected function style(string $style, string $value, array $attr = [])

if (null === $this->handlesHrefGracefully) {
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR')
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100);
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100)
&& !isset($_SERVER['IDEA_INITIAL_DIRECTORY']);
}

if (isset($attr['ellipsis'], $attr['ellipsis-type'])) {
Expand Down