Skip to content

Commit 2cd64c0

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into develop
2 parents 552b9d3 + d0c7e2c commit 2cd64c0

File tree

3 files changed

+69
-15
lines changed

3 files changed

+69
-15
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ This file is a running track of new features and fixes to each version of the pa
33

44
This project follows [Semantic Versioning](http://semver.org) guidelines.
55

6+
## v1.4.0
7+
### Fixed
8+
* Removes the use of tagging when storing server resource usage in the cache. This addresses errors encountered when using the `file` driver.
9+
* Fixes Wings response handling if Wings returns an error response with a 200-level status code that would improperly be passed back to the client as a successful request.
10+
* Fixes use of JSON specific functions in SQL queries to better support MariaDB users.
11+
* Fixes a migration that could fail on some MySQL/MariaDB setups when trying to encrypt node token values.
12+
13+
### Changed
14+
* Increases the maximum length allowed for a server name using the Rust egg.
15+
* Updated server resource utilization API call to Wings to use new API response format used by `Wings@1.4.0`.
16+
617
## v1.3.2
718
### Fixed
819
* Fixes self-upgrade incorrectly executing the command to un-tar downloaded archives.

app/Traits/Commands/EnvironmentWriterTrait.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Traits\Commands;
114

125
use Pterodactyl\Exceptions\PterodactylException;
136

147
trait EnvironmentWriterTrait
158
{
9+
/**
10+
* Escapes an environment value by looking for any characters that could
11+
* reasonablly cause environment parsing issues. Those values are then wrapped
12+
* in quotes before being returned.
13+
*/
14+
public function escapeEnvironmentValue(string $value): string
15+
{
16+
if (!preg_match('/^\"(.*)\"$/', $value) && preg_match('/([^\w.\-+\/])+/', $value)) {
17+
return sprintf('"%s"', addslashes($value));
18+
}
19+
20+
return $value;
21+
}
22+
1623
/**
1724
* Update the .env file for the application using the passed in values.
1825
*
@@ -28,14 +35,7 @@ public function writeToEnvironment(array $values = [])
2835
$saveContents = file_get_contents($path);
2936
collect($values)->each(function ($value, $key) use (&$saveContents) {
3037
$key = strtoupper($key);
31-
// If the key value is not sorrounded by quotation marks, and contains anything that could reasonably
32-
// cause environment parsing issues, wrap it in quotes before writing it. This also adds slashes to the
33-
// value to ensure quotes within it don't cause us issues.
34-
if (!preg_match('/^\"(.*)\"$/', $value) && preg_match('/([^\w.\-+\/])+/', $value)) {
35-
$value = sprintf('"%s"', addslashes($value));
36-
}
37-
38-
$saveValue = sprintf('%s=%s', $key, $value);
38+
$saveValue = sprintf('%s=%s', $key, $this->escapeEnvironmentValue($value));
3939

4040
if (preg_match_all('/^' . $key . '=(.*)$/m', $saveContents) < 1) {
4141
$saveContents = $saveContents . PHP_EOL . $saveValue;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Pterodactyl\Tests\Unit\Helpers;
4+
5+
use Pterodactyl\Tests\TestCase;
6+
use Pterodactyl\Traits\Commands\EnvironmentWriterTrait;
7+
8+
class EnvironmentWriterTraitTest extends TestCase
9+
{
10+
/**
11+
* @dataProvider variableDataProvider
12+
*/
13+
public function testVariableIsEscapedProperly($input, $expected)
14+
{
15+
$output = (new FooClass())->escapeEnvironmentValue($input);
16+
17+
$this->assertSame($expected, $output);
18+
}
19+
20+
public function variableDataProvider(): array
21+
{
22+
return [
23+
['foo', 'foo'],
24+
['abc123', 'abc123'],
25+
['val"ue', '"val\"ue"'],
26+
['my test value', '"my test value"'],
27+
['mysql_p@assword', '"mysql_p@assword"'],
28+
['mysql_p#assword', '"mysql_p#assword"'],
29+
['mysql p@$$word', '"mysql p@$$word"'],
30+
['mysql p%word', '"mysql p%word"'],
31+
['mysql p#word', '"mysql p#word"'],
32+
['abc_@#test', '"abc_@#test"'],
33+
['test 123 $$$', '"test 123 $$$"'],
34+
['#password%', '"#password%"'],
35+
['$pass ', '"$pass "'],
36+
];
37+
}
38+
}
39+
40+
class FooClass
41+
{
42+
use EnvironmentWriterTrait;
43+
}

0 commit comments

Comments
 (0)