Skip to content

Commit d27667a

Browse files
authored
Merge pull request #8 from msztorc/pquote-fix
url quote - fix
2 parents f64e609 + 63bc91e commit d27667a

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ vendor/
55
tests/.env
66
phpunit.xml
77
.php_cs.cache
8+
.phpunit.result.cache

.php-cs-fixer.cache

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/Env.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ public function deleteVariable(string $key, bool $write = true): bool
131131
return true;
132132
}
133133

134+
private function _preg_quote_except(string $str, string $exclude, ?string $delimiter = null): string
135+
{
136+
$str = preg_quote($str, $delimiter);
137+
$from = [];
138+
$to = [];
139+
140+
for ($i = 0; $i < strlen($exclude); $i++) {
141+
$from[] = '\\' . $exclude[$i];
142+
$to[] = $exclude[$i];
143+
}
144+
145+
return (count($from) && count($to)) ? str_replace($from, $to, $str) : $str;
146+
}
147+
134148
/**
135149
* Check and prepare value to be safe
136150
* @param string $value
@@ -142,7 +156,7 @@ private function _prepareValue(string $value): string
142156
$value = '"' . $value . '"';
143157
}
144158

145-
return preg_quote($value);
159+
return $this->_preg_quote_except($value, ':.');
146160
}
147161

148162
private function _stripQuotes(string $value): string

tests/EnvArtisanTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,17 @@ public function testEnvDelAll(): void
138138
->assertExitCode(0);
139139
}
140140
}
141+
142+
public function testUrls(): void
143+
{
144+
$app_url = 'https://mywebsite.com';
145+
146+
$this->artisan('env:set', ['key' => 'APP_URL' .'=' .$app_url])
147+
->expectsOutput("Environment variable with key 'APP_URL' has been set to '{$app_url}'")
148+
->assertExitCode(0);
149+
150+
$this->artisan('env:get', ['key' => 'APP_URL'])
151+
->expectsOutput($app_url)
152+
->assertExitCode(0);
153+
}
141154
}

tests/EnvClassTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,13 @@ public function testEnvDelAll(): void
199199
unset($env);
200200
}
201201
}
202+
203+
public function testUrls(): void
204+
{
205+
$env = new Env();
206+
$app_url = 'https://mywebsite.com';
207+
$env->setValue('APP_URL', $app_url);
208+
$ver_value = $env->getValue('APP_URL');
209+
$this->assertEquals($app_url, $ver_value);
210+
}
202211
}

0 commit comments

Comments
 (0)