vibe.d icon indicating copy to clipboard operation
vibe.d copied to clipboard

Invalid character in internet path.

Open Aphexus opened this issue 7 months ago • 6 comments

XHRPOST C:/Ebooks/Ashby W.R - An Introduction to Cybernetics [Chapman Hall 1956].pdf

400 - Bad Request Bad Request Internal error information:

[email protected]\vibe-core\source\vibe\core\path.d(445): Invalid character in internet path.

This is with all chars escaped(I've tried many things). It seems to be the [ ]'s that are failing(even when they are escaped). Other strings work just fine. If I replace the [ ] with, say, - then it works but, of course that is problematic.

I can't seem to escape this in some arbitrary way either such as using %FE and %FF. I guess I can base64 encode everything.

static string validatePath(string path)
@nogc {
	import std.algorithm.comparison : among;

	// skip UNC prefix
	if (path.startsWith("\\\\")) {
		path = path[2 .. $];
		while (path.length && !isSeparator(path[0])) {
			if (path[0] < 32 || path[0].among('<', '>', '|'))
				return "Invalid character in UNC host name.";
			path = path[1 .. $];
		}
		if (path.length) path = path[1 .. $];
	}

	// stricter validation for the rest
	bool had_sep = false;
	foreach (i, char c; path) {
		if (c < 32 || c.among!('<', '>', '|', '?'))
			return "Invalid character in path.";
		if (isSeparator(c)) had_sep = true;
		else if (c == ':' && (had_sep || i+1 < path.length && !isSeparator(path[i+1])))
			return "Colon in path that is not part of a drive name.";

	}
	return null;
}

Aphexus avatar Nov 27 '23 11:11 Aphexus