aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/3rdparty/icewind/smb/src/AbstractShare.php
blob: 77f50e4ca9dff73e63a5ae6de5c05a1612a26d88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
/**
 * SPDX-FileCopyrightText: 2015 Robin Appelman <robin@icewind.nl>
 * SPDX-License-Identifier: MIT
 */

namespace Icewind\SMB;

use Icewind\SMB\Exception\InvalidPathException;

abstract class AbstractShare implements IShare {
	/** @var string[] */
	private $forbiddenCharacters;

	public function __construct() {
		$this->forbiddenCharacters = ['?', '<', '>', ':', '*', '|', '"', chr(0), "\n", "\r"];
	}

	/**
	 * @param string $path
	 * @throws InvalidPathException
	 */
	protected function verifyPath(string $path): void {
		foreach ($this->forbiddenCharacters as $char) {
			if (strpos($path, $char) !== false) {
				throw new InvalidPathException('Invalid path, "' . $char . '" is not allowed');
			}
		}
	}

	/**
	 * @param string[] $charList
	 */
	public function setForbiddenChars(array $charList): void {
		$this->forbiddenCharacters = $charList;
	}
}