//#region src/v2/blocks/operation-block/helpers/apply-allow-reserved-to-url.ts
/**
* Reserved characters we can safely decode in query values when OpenAPI
* `allowReserved` is enabled.
*
* We intentionally keep percent-encodings for characters that can break query
* parsing (`#`, `&`, `=`, `?`, `[`, `]`) or change x-www-form-urlencoded
* semantics (`+`).
*
* @see https://spec.openapis.org/oas/v3.1.0.html#fixed-fields-10
*/
var DECODABLE_RESERVED_CHARACTERS_BY_PERCENT_ENCODING = {
	"21": "!",
	"24": "$",
	"27": "'",
	"28": "(",
	"29": ")",
	"2A": "*",
	"2C": ",",
	"2F": "/",
	"3A": ":",
	"3B": ";",
	"40": "@"
};
var decodeReservedCharacters = (value) => value.replace(/%([0-9A-Fa-f]{2})/g, (match, code) => DECODABLE_RESERVED_CHARACTERS_BY_PERCENT_ENCODING[code.toUpperCase()] ?? match);
var decodeQueryKey = (key) => {
	try {
		return decodeURIComponent(key.replaceAll("+", "%20"));
	} catch {
		return key;
	}
};
/**
* Decodes reserved character percent-encodings only for query keys marked with
* OpenAPI's `allowReserved: true`.
*/
var applyAllowReservedToUrl = (url, allowReservedQueryParameters) => {
	if (allowReservedQueryParameters.size === 0) return url;
	const queryStart = url.indexOf("?");
	if (queryStart === -1) return url;
	const hashStart = url.indexOf("#", queryStart);
	const urlPrefix = url.slice(0, queryStart + 1);
	const query = hashStart === -1 ? url.slice(queryStart + 1) : url.slice(queryStart + 1, hashStart);
	const hash = hashStart === -1 ? "" : url.slice(hashStart);
	if (!query) return url;
	return `${urlPrefix}${query.split("&").map((segment) => {
		if (!segment) return segment;
		const equalsIndex = segment.indexOf("=");
		const rawKey = equalsIndex === -1 ? segment : segment.slice(0, equalsIndex);
		const key = decodeQueryKey(rawKey);
		if (!allowReservedQueryParameters.has(key) || equalsIndex === -1) return segment;
		return `${rawKey}=${decodeReservedCharacters(segment.slice(equalsIndex + 1))}`;
	}).join("&")}${hash}`;
};
//#endregion
export { applyAllowReservedToUrl };

//# sourceMappingURL=apply-allow-reserved-to-url.js.map