Skip to content

Commit 5f2603e

Browse files
committed
reset filesystem mimetype format before doing acl things
1 parent f4d055b commit 5f2603e

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

src/WAC.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public function setBaseUrl($url) {
2222
}
2323

2424
public function addWACHeaders($request, $response, $webId) {
25+
$currentFormat = $this->filesystem->getAdapter()->getFormat(); // keep the format so we can put it back later. prevents the acl file from being converted;
26+
$this->filesystem->getAdapter()->setFormat('');
2527
$uri = $request->getUri();
2628
$userGrants = $this->getWACGrants($this->getUserGrants($uri, $webId), $uri);
2729
$publicGrants = $this->getWACGrants($this->getPublicGrants($uri), $uri);
@@ -36,7 +38,7 @@ public function addWACHeaders($request, $response, $webId) {
3638

3739
$response = $response->withHeader("Link", '<.acl>; rel="acl"');
3840
$response = $response->withHeader("WAC-Allow", implode(",", $wacHeaders));
39-
41+
$this->filesystem->getAdapter()->setFormat($currentFormat);
4042
return $response;
4143
}
4244

@@ -51,10 +53,10 @@ public function isAllowed($request, $webId, $origin=false, $allowedOrigins=[]) {
5153
$uri = $request->getUri();
5254
$parentUri = $this->getParentUri($uri);
5355

54-
// @FIXME: $origin can be anything at this point, null, string, array, bool
55-
// This causes trouble downstream where an unchecked `parse_url($origin)['host'];` occurs
56+
// @FIXME: $origin can be anything at this point, null, string, array, bool
57+
// This causes trouble downstream where an unchecked `parse_url($origin)['host'];` occurs
5658

57-
foreach ($requestedGrants as $requestedGrant) {
59+
foreach ($requestedGrants as $requestedGrant) {
5860
switch ($requestedGrant['type']) {
5961
case "resource":
6062
if ($this->isPublicGranted($requestedGrant['grants'], $uri)) {
@@ -124,9 +126,9 @@ private function isUserGranted($requestedGrants, $uri, $webId) {
124126
}
125127

126128
private function isOriginGranted($requestedGrants, $uri, $origin, $allowedOrigins) {
127-
if (is_array($origin)) {
128-
$origin = reset($origin);
129-
}
129+
if (is_array($origin)) {
130+
$origin = reset($origin);
131+
}
130132

131133
if (!$origin) {
132134
return true;
@@ -306,7 +308,7 @@ private function getAclPath($path) {
306308
foreach ($aclOptions as $aclPath) {
307309
if (
308310
$this->filesystem->has($aclPath)
309-
&& $this->filesystem->read($aclPath) !== false
311+
&& $this->filesystem->read($aclPath) !== false
310312
) {
311313
return $aclPath;
312314
}
@@ -513,12 +515,12 @@ private function getParentUri($uri) {
513515
}
514516
private function getWACGrants($grants, $uri) {
515517
$wacGrants = array();
516-
if (!isset($grants['accessTo'])) {
517-
$grants['accessTo'] = [];
518-
}
519-
if (!isset($grants['default'])) {
520-
$grants['default'] = [];
521-
}
518+
if (!isset($grants['accessTo'])) {
519+
$grants['accessTo'] = [];
520+
}
521+
if (!isset($grants['default'])) {
522+
$grants['default'] = [];
523+
}
522524
foreach ((array)$grants['accessTo'] as $grant => $grantedUri) {
523525
if ($this->arePathsEqual($grantedUri, $uri)) {
524526
$wacGrants[] = $this->grantToWac($grant);

0 commit comments

Comments
 (0)