Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/infrastructure/env/PhabricatorScopedEnv.php b/src/infrastructure/env/PhabricatorScopedEnv.php
index 4e92ac2bbe..4e441778b2 100644
--- a/src/infrastructure/env/PhabricatorScopedEnv.php
+++ b/src/infrastructure/env/PhabricatorScopedEnv.php
@@ -1,72 +1,76 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Scope guard to hold a temporary environment. See @{class:PhabricatorEnv} for
* instructions on use.
*
* @task internal Internals
* @task override Overriding Environment Configuration
*/
final class PhabricatorScopedEnv {
private $key;
+ private $isPopped = false;
/* -( Overriding Environment Configuration )------------------------------- */
/**
* Override a configuration key in this scope, setting it to a new value.
*
* @param string Key to override.
* @param wild New value.
* @return this
*
* @task override
*/
public function overrideEnvConfig($key, $value) {
PhabricatorEnv::overrideEnvConfig(
$this->key,
$key,
$value);
return $this;
}
/* -( Internals )---------------------------------------------------------- */
/**
*
* @task internal
*/
public function __construct($stack_key) {
$this->key = $stack_key;
}
/**
* Release the scoped environment.
*
* @return void
* @task internal
*/
public function __destruct() {
- PhabricatorEnv::popEnvironment($this->key);
+ if (!$this->isPopped) {
+ PhabricatorEnv::popEnvironment($this->key);
+ $this->isPopped = true;
+ }
}
}
diff --git a/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php b/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php
index a5b1814285..9a01ea313a 100644
--- a/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php
+++ b/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php
@@ -1,108 +1,123 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorEnvTestCase extends PhabricatorTestCase {
public function testLocalWebResource() {
$map = array(
'/' => true,
'/D123' => true,
'/path/to/something/' => true,
"/path/to/\nHeader: x" => false,
'http://evil.com/' => false,
'//evil.com/evil/' => false,
'javascript:lol' => false,
'' => false,
null => false,
);
foreach ($map as $uri => $expect) {
$this->assertEqual(
$expect,
PhabricatorEnv::isValidLocalWebResource($uri),
"Valid local resource: {$uri}");
}
}
public function testRemoteWebResource() {
$map = array(
'http://example.com/' => true,
'derp://example.com/' => false,
'javascript:alert(1)' => false,
);
foreach ($map as $uri => $expect) {
$this->assertEqual(
$expect,
PhabricatorEnv::isValidRemoteWebResource($uri),
"Valid remote resource: {$uri}");
}
}
public function testOverrides() {
$outer = PhabricatorEnv::beginScopedEnv();
$outer->overrideEnvConfig('test.value', 1);
$this->assertEqual(1, PhabricatorEnv::getEnvConfig('test.value'));
$inner = PhabricatorEnv::beginScopedEnv();
$inner->overrideEnvConfig('test.value', 2);
$this->assertEqual(2, PhabricatorEnv::getEnvConfig('test.value'));
+ if (phutil_is_hiphop_runtime()) {
+ $inner->__destruct();
+ }
unset($inner);
$this->assertEqual(1, PhabricatorEnv::getEnvConfig('test.value'));
+ if (phutil_is_hiphop_runtime()) {
+ $outer->__destruct();
+ }
unset($outer);
}
public function testOverrideOrder() {
$outer = PhabricatorEnv::beginScopedEnv();
$middle = PhabricatorEnv::beginScopedEnv();
$inner = PhabricatorEnv::beginScopedEnv();
$caught = null;
try {
+ if (phutil_is_hiphop_runtime()) {
+ $middle->__destruct();
+ }
unset($middle);
} catch (Exception $ex) {
$caught = $ex;
}
$this->assertEqual(
true,
$caught instanceof Exception,
"Destroying a scoped environment which is not on the top of the stack ".
"should throw.");
$caught = null;
try {
+ if (phutil_is_hiphop_runtime()) {
+ $inner->__destruct();
+ }
unset($inner);
} catch (Exception $ex) {
$caught = $ex;
}
$this->assertEqual(
true,
$caught instanceof Exception,
"Destroying a scoped environment which is not on the top of the stack ".
"should throw.");
// Although we popped the other two out-of-order, we still expect to end
// up in the right state after handling the exceptions, so this should
// execute without issues.
+ if (phutil_is_hiphop_runtime()) {
+ $outer->__destruct();
+ }
unset($outer);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Jul 28, 4:12 AM (1 w, 20 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
186410
Default Alt Text
(5 KB)

Event Timeline